Class: VerticalResponse::API::OAuth
- Defined in:
- lib/verticalresponse/api/oauth.rb
Instance Attribute Summary
Attributes inherited from Client
Class Method Summary collapse
- .access_token(auth_code, redirect_uri = "", client_id = "", client_secret = "") ⇒ Object
-
.assign_headers(*args) ⇒ Object
Overwrite this method as we don’t need to setup headers for OAuth calls.
-
.authorize(client_id = "", redirect_uri = "") ⇒ Object
client_id is the application key.
- .resource_uri_suffix ⇒ Object
Instance Method Summary collapse
- #contacts(params = {}, *path_prefix) ⇒ Object
-
#create_contacts(contact_details, *path_prefix) ⇒ Object
One or more contacts; if creating more => custom fields aren’t created remotely Attempt to create custom fields remotely => error.
- #custom_fields(params = {}) ⇒ Object
- #find_contact(contact_id, params = {}) ⇒ Object
- #find_contact_by_email(email, params = {}) ⇒ Object
-
#find_list(list_id, params = {}) ⇒ Object
Afterwards, can use ‘create_contact’, etc.
-
#initialize(access_token) ⇒ OAuth
constructor
A new instance of OAuth.
-
#lists(params = {}) ⇒ Object
We want to access instances of OAuth with OOP, so we’ll include some wrappers that let us use do the following: client = OAuth.new(access_token) client.lists client.contacts.
Methods inherited from Client
add_default_query_param, base_service_uri, base_uri, base_uri_with_prefix, build_params, build_query_params, config, default_query_params, embed_resource, resource_uri, resource_uri_with_prefix, resource_uri_with_token
Constructor Details
#initialize(access_token) ⇒ OAuth
15 16 17 |
# File 'lib/verticalresponse/api/oauth.rb', line 15 def initialize(access_token) @access_token = access_token end |
Class Method Details
.access_token(auth_code, redirect_uri = "", client_id = "", client_secret = "") ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/verticalresponse/api/oauth.rb', line 37 def access_token(auth_code, redirect_uri = "", client_id = "", client_secret = "") get( resource_uri('access_token'), build_query_params({ :client_id => client_id, :client_secret => client_secret, :code => auth_code, :redirect_uri => redirect_uri }) ) end |
.assign_headers(*args) ⇒ Object
Overwrite this method as we don’t need to setup headers for OAuth calls
22 23 |
# File 'lib/verticalresponse/api/oauth.rb', line 22 def assign_headers(*args) end |
.authorize(client_id = "", redirect_uri = "") ⇒ Object
client_id is the application key
30 31 32 33 34 35 |
# File 'lib/verticalresponse/api/oauth.rb', line 30 def (client_id = "", redirect_uri = "") get( resource_uri('authorize'), build_query_params({ :client_id => client_id, :redirect_uri => redirect_uri }) ) end |
.resource_uri_suffix ⇒ Object
25 26 27 |
# File 'lib/verticalresponse/api/oauth.rb', line 25 def resource_uri_suffix ['oauth'] end |
Instance Method Details
#contacts(params = {}, *path_prefix) ⇒ Object
79 80 81 82 |
# File 'lib/verticalresponse/api/oauth.rb', line 79 def contacts(params = {}, *path_prefix) params.merge!({access_token: @access_token}) VerticalResponse::API::Contact.all(params, path_prefix) end |
#create_contacts(contact_details, *path_prefix) ⇒ Object
One or more contacts; if creating more => custom fields aren’t created remotely Attempt to create custom fields remotely => error
For multiple, use contacts: […,…]
99 100 101 102 103 104 105 |
# File 'lib/verticalresponse/api/oauth.rb', line 99 def create_contacts(contact_details, *path_prefix) contact_details = { contacts: contact_details } if contact_details.is_a?(Array) VerticalResponse::API::Contact.create( contact_details.merge(access_token: @access_token), path_prefix ) end |
#custom_fields(params = {}) ⇒ Object
107 108 109 110 |
# File 'lib/verticalresponse/api/oauth.rb', line 107 def custom_fields(params = {}) params.merge!({access_token: @access_token}) VerticalResponse::API::CustomField.all(params) end |
#find_contact(contact_id, params = {}) ⇒ Object
84 85 86 87 |
# File 'lib/verticalresponse/api/oauth.rb', line 84 def find_contact(contact_id, params = {}) params.merge!({access_token: @access_token}) VerticalResponse::API::Contact.find(contact_id, params) end |
#find_contact_by_email(email, params = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/verticalresponse/api/oauth.rb', line 89 def find_contact_by_email(email, params = {}) params.merge!({access_token: @access_token}) params.merge!({email_address: email}) VerticalResponse::API::Contact.find_by_email(params) end |
#find_list(list_id, params = {}) ⇒ Object
Afterwards, can use ‘create_contact’, etc.
74 75 76 77 |
# File 'lib/verticalresponse/api/oauth.rb', line 74 def find_list(list_id, params = {}) params.merge!({access_token: @access_token}) VerticalResponse::API::List.find(list_id, params) end |
#lists(params = {}) ⇒ Object
We want to access instances of OAuth with OOP, so we’ll include some wrappers that let us use do the following:
client = OAuth.new(access_token)
client.lists
client.contacts
Please note, using static libraries isn’t “object-oriented”. Using instances is. The client in the example above is an example of an instance. This whole gem uses libraries instead of instances which is kindof bad.
TODO: this whole gem should be more object-oriented, but for now this should work
68 69 70 71 |
# File 'lib/verticalresponse/api/oauth.rb', line 68 def lists(params = {}) params.merge!({access_token: @access_token}) VerticalResponse::API::List.all(params) end |