Class: FastBound::Contact

Inherits:
Base
  • Object
show all
Includes:
API
Defined in:
lib/fastbound-ruby/contact.rb

Constant Summary collapse

CREATE_AND_EDIT_ATTRS =
%i(
  external_id ffl_number ffl_expires lookup_ffl license_name trade_name sotein sot_class business_type
  organization_name first_name middle_name last_name premise_address_1 premise_address_2 premise_city
  premise_county premise_state premise_zip_code premise_country phone_number fax email_address
).freeze
CREATE_AND_EDIT_LICENSE_ATTRS =
{
  permitted: %i( type number expiration copy_on_file ).freeze,
  required:  %i( type number ).freeze
}
MERGE_ATTRS =
{
  permitted: %i( winning_contact_id losing_contact_id ).freeze,
  required:  %i( winning_contact_id losing_contact_id ).freeze
}
ENDPOINTS =
{
  list:                 "contacts?%s".freeze,
  create:               "contacts".freeze,
  edit:                 "contacts/%s".freeze,
  fetch:                "contacts/%s".freeze,
  fetch_by_external_id: "contacts/getbyexternalid/%s".freeze,
  delete:               "contacts/%s".freeze,
  merge:                "contacts/merge".freeze,
  create_license:       "contacts/%s/licenses".freeze,
  edit_license:         "contacts/%s/licenses/%s".freeze,
  fetch_license:        "contacts/%s/licenses/%s".freeze,
  delete_license:       "contacts/%s/licenses/%s".freeze,
}

Constants included from API

API::FILE_UPLOAD_ATTRS, API::ROOT_URL, API::USER_AGENT

Instance Method Summary collapse

Methods included from API

#delete_request, #get_request, #post_file_request, #post_request, #put_request

Constructor Details

#initialize(client) ⇒ Contact

Returns a new instance of Contact.



38
39
40
# File 'lib/fastbound-ruby/contact.rb', line 38

def initialize(client)
  @client = client
end

Instance Method Details

#create(contact_data) ⇒ Object



48
49
50
51
52
53
# File 'lib/fastbound-ruby/contact.rb', line 48

def create(contact_data)
  endpoint = ENDPOINTS[:create]
  contact_data = standardize_body_data(contact_data, CREATE_AND_EDIT_ATTRS)

  post_request(@client, endpoint, contact_data)
end

#create_license(contact_id, license_data) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/fastbound-ruby/contact.rb', line 89

def create_license(contact_id, license_data)
  requires!(license_data, *CREATE_AND_EDIT_LICENSE_ATTRS[:required])

  endpoint = ENDPOINTS[:create_license] % contact_id
  license_data = standardize_body_data(license_data, CREATE_AND_EDIT_LICENSE_ATTRS[:permitted])

  post_request(@client, endpoint, license_data)
end

#delete(contact_id) ⇒ Object



74
75
76
77
78
# File 'lib/fastbound-ruby/contact.rb', line 74

def delete(contact_id)
  endpoint = ENDPOINTS[:delete] % contact_id

  delete_request(@client, endpoint)
end

#delete_license(contact_id, license_id) ⇒ Object



111
112
113
114
115
# File 'lib/fastbound-ruby/contact.rb', line 111

def delete_license(contact_id, license_id)
  endpoint = ENDPOINTS[:delete_license] % [contact_id, license_id]

  delete_request(@client, endpoint)
end

#edit(contact_id, contact_data) ⇒ Object



55
56
57
58
59
60
# File 'lib/fastbound-ruby/contact.rb', line 55

def edit(contact_id, contact_data)
  endpoint = ENDPOINTS[:edit] % contact_id
  contact_data = standardize_body_data(contact_data, CREATE_AND_EDIT_ATTRS)

  put_request(@client, endpoint, contact_data)
end

#edit_license(contact_id, license_data) ⇒ Object



98
99
100
101
102
103
# File 'lib/fastbound-ruby/contact.rb', line 98

def edit_license(contact_id, license_data)
  endpoint = ENDPOINTS[:edit_license] % contact_id
  license_data = standardize_body_data(license_data, CREATE_AND_EDIT_LICENSE_ATTRS[:permitted])

  put_request(@client, endpoint, license_data)
end

#fetch(contact_id) ⇒ Object



62
63
64
65
66
# File 'lib/fastbound-ruby/contact.rb', line 62

def fetch(contact_id)
  endpoint = ENDPOINTS[:fetch] % contact_id

  get_request(@client, endpoint)
end

#fetch_by_external_id(external_id) ⇒ Object



68
69
70
71
72
# File 'lib/fastbound-ruby/contact.rb', line 68

def fetch_by_external_id(external_id)
  endpoint = ENDPOINTS[:fetch_by_external_id] % external_id

  get_request(@client, endpoint)
end

#fetch_license(contact_id, license_id) ⇒ Object



105
106
107
108
109
# File 'lib/fastbound-ruby/contact.rb', line 105

def fetch_license(contact_id, license_id)
  endpoint = ENDPOINTS[:fetch_license] % [contact_id, license_id]

  get_request(@client, endpoint)
end

#list(params = {}) ⇒ Object



42
43
44
45
46
# File 'lib/fastbound-ruby/contact.rb', line 42

def list(params = {})
  endpoint = ENDPOINTS[:list] % convert_params_to_request_query(params)

  get_request(@client, endpoint)
end

#merge(merge_data) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/fastbound-ruby/contact.rb', line 80

def merge(merge_data)
  requires!(merge_data, *MERGE_ATTRS[:required])

  endpoint = ENDPOINTS[:merge]
  merge_data = standardize_body_data(merge_data, MERGE_ATTRS[:permitted])

  post_request(@client, endpoint, merge_data)
end