verticalresponse 0.1.3 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -11
- data/lib/verticalresponse.rb +17 -12
- data/lib/{client.rb → verticalresponse/api/client.rb} +44 -3
- data/lib/{contact.rb → verticalresponse/api/contact.rb} +13 -4
- data/lib/{custom_field.rb → verticalresponse/api/custom_field.rb} +2 -3
- data/lib/{email.rb → verticalresponse/api/email.rb} +2 -3
- data/lib/{error.rb → verticalresponse/api/error.rb} +0 -0
- data/lib/{list.rb → verticalresponse/api/list.rb} +18 -9
- data/lib/{message.rb → verticalresponse/api/message.rb} +3 -3
- data/lib/verticalresponse/api/oauth.rb +113 -0
- data/lib/{resource.rb → verticalresponse/api/resource.rb} +44 -24
- data/lib/{response.rb → verticalresponse/api/response.rb} +6 -3
- data/lib/{social_post.rb → verticalresponse/api/social_post.rb} +2 -3
- metadata +31 -17
- data/lib/oauth.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea638bd9b5bc61e712489d4cdea16315cc2899ab
|
4
|
+
data.tar.gz: 673029928047e551a3b94e96797b76c86256070c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 746f527074d0599a6aec04addd475079282b6ea5587165bb26f61433f75cb8fa7a1f463e86d0b9a23456021b67dd70e13637b439b4d0aaffa3da812e74744387
|
7
|
+
data.tar.gz: b0c59b01284d31c53552184cc4b7ddba9a489339ede35e0daa6581f007a61ffc411cff5f8605957f1a32f3d1eee6528c95f6a4fc504d3c3f297c8859a45d5cc2
|
data/README.md
CHANGED
@@ -10,22 +10,48 @@ Based on https://github.com/VerticalResponse/v1wrappers/
|
|
10
10
|
New Functionality
|
11
11
|
-----------------
|
12
12
|
|
13
|
-
Allows instantiating oauth clients by access_token, to access the VerticalResponse API in an object-oriented fashion.
|
13
|
+
Allows instantiating oauth clients by access_token, to access the VerticalResponse API in an object-oriented fashion. The calls are object-oriented in the sense that you can instantate a client with its access_token. This is not possible with the original wrappers.
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
|
17
|
-
```
|
16
|
+
client = VerticalResponse::API::OAuth.new access_token
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
oauth_client.lists
|
22
|
-
```
|
18
|
+
# Get all lists
|
19
|
+
client.lists
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
# Get a specific list
|
22
|
+
client.find_list("<id>")
|
23
|
+
|
24
|
+
# Get contacts in a specific list
|
25
|
+
client.find_list("<id>").contacts
|
26
|
+
|
27
|
+
# Create multiple contacts in a specific list
|
28
|
+
client.find_list("<id>").create_contacts([{
|
29
|
+
email: "some@email.com",
|
30
|
+
first_name: "some first name",
|
31
|
+
last_name: "some last name",
|
32
|
+
custom: {
|
33
|
+
field: "some custom field"
|
34
|
+
}
|
35
|
+
},
|
36
|
+
{
|
37
|
+
email: "another@email.com",
|
38
|
+
first_name: "another first name",
|
39
|
+
last_name: "another last name",
|
40
|
+
custom: {
|
41
|
+
field: "another custom field"
|
42
|
+
}
|
43
|
+
}
|
44
|
+
])
|
45
|
+
|
46
|
+
# Get all contacts
|
47
|
+
client.contacts
|
48
|
+
|
49
|
+
# Get all custom fields
|
50
|
+
client.custom_fields
|
27
51
|
```
|
28
52
|
|
53
|
+
And a few other calls as well. Not all wrapper methods are supported, but you're more than welcome to implement them yourself and submit pull requests.
|
54
|
+
|
29
55
|
Requirements
|
30
56
|
----------
|
31
57
|
Ruby 1.9+ (compatible with Ruby 2.1.1)
|
@@ -36,4 +62,4 @@ Note: I only tested these requirements as much as I needed to (not for all funct
|
|
36
62
|
|
37
63
|
Contribute
|
38
64
|
----------
|
39
|
-
|
65
|
+
The features of this gem were built as needed, and it is pretty limited. Contributions are more than welcome!
|
data/lib/verticalresponse.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
|
-
require_relative '
|
4
|
-
|
5
|
-
require_relative '
|
6
|
-
require_relative '
|
7
|
-
require_relative '
|
8
|
-
require_relative '
|
9
|
-
require_relative '
|
10
|
-
require_relative '
|
11
|
-
require_relative '
|
12
|
-
require_relative '
|
13
|
-
require_relative '
|
3
|
+
require_relative 'verticalresponse/api/oauth.rb'
|
4
|
+
|
5
|
+
require_relative 'verticalresponse/api/client.rb'
|
6
|
+
require_relative 'verticalresponse/api/contact.rb'
|
7
|
+
require_relative 'verticalresponse/api/custom_field.rb'
|
8
|
+
require_relative 'verticalresponse/api/email.rb'
|
9
|
+
require_relative 'verticalresponse/api/error.rb'
|
10
|
+
require_relative 'verticalresponse/api/list.rb'
|
11
|
+
require_relative 'verticalresponse/api/message.rb'
|
12
|
+
require_relative 'verticalresponse/api/resource.rb'
|
13
|
+
require_relative 'verticalresponse/api/response.rb'
|
14
|
+
require_relative 'verticalresponse/api/social_post.rb'
|
14
15
|
|
15
16
|
module VerticalResponse
|
17
|
+
API_VERSION = "v1"
|
18
|
+
|
16
19
|
CONFIG = {
|
17
20
|
host: 'vrapi.verticalresponse.com',
|
18
21
|
port: "",
|
19
22
|
protocol: 'https'
|
20
23
|
}
|
21
|
-
end
|
24
|
+
end
|
25
|
+
|
26
|
+
$LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
|
@@ -8,6 +8,8 @@ require_relative 'response'
|
|
8
8
|
module VerticalResponse
|
9
9
|
module API
|
10
10
|
class Client
|
11
|
+
attr_reader :access_token
|
12
|
+
|
11
13
|
include HTTParty
|
12
14
|
|
13
15
|
format :json
|
@@ -20,7 +22,7 @@ module VerticalResponse
|
|
20
22
|
# Assign the headers required by our partner Mashery
|
21
23
|
def assign_headers(headers_info = {})
|
22
24
|
access_token = headers_info[:access_token]
|
23
|
-
add_default_query_param(:access_token, access_token)
|
25
|
+
add_default_query_param(:access_token, access_token) unless access_token.nil?
|
24
26
|
end
|
25
27
|
|
26
28
|
def embed_resource(resource, resource_id = nil)
|
@@ -32,7 +34,7 @@ module VerticalResponse
|
|
32
34
|
# It builds the URI based on the values from the API configuration file.
|
33
35
|
# 'host' must be defined (unless host_uri is specified as an input param)
|
34
36
|
# otherwise the method will raise an exception.
|
35
|
-
def
|
37
|
+
def base_service_uri(host_uri = nil)
|
36
38
|
uri = host_uri
|
37
39
|
unless uri
|
38
40
|
unless VerticalResponse::CONFIG[:host]
|
@@ -58,6 +60,23 @@ module VerticalResponse
|
|
58
60
|
URI.join(uri, File.join(*paths))
|
59
61
|
end
|
60
62
|
|
63
|
+
def base_uri(host_uri = nil)
|
64
|
+
@base_uri ||= File.join(base_service_uri(host_uri).to_s, *resource_uri_suffix)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Allow getting contacts from a list, creating contacts inside a list, etc.
|
68
|
+
# This works better than embed_resource, since it avoids conflicts between
|
69
|
+
# multiple actors. In a multithreaded environment this is obvious, but
|
70
|
+
# in a multi-process environment conflicts can still happen, so we want
|
71
|
+
# to set the prefix of a uri on instances, not at the class level.
|
72
|
+
def base_uri_with_prefix(*prefix)
|
73
|
+
File.join(base_service_uri.to_s, *prefix, *resource_uri_suffix)
|
74
|
+
end
|
75
|
+
|
76
|
+
def resource_uri_suffix
|
77
|
+
[]
|
78
|
+
end
|
79
|
+
|
61
80
|
def build_params(params, query_params = {})
|
62
81
|
request_params = {}
|
63
82
|
request_params[:body] = params if params
|
@@ -97,6 +116,27 @@ module VerticalResponse
|
|
97
116
|
end
|
98
117
|
uri
|
99
118
|
end
|
119
|
+
|
120
|
+
def resource_uri_with_prefix(prefix, *additional_paths)
|
121
|
+
uri = base_uri_with_prefix(prefix)
|
122
|
+
if additional_paths.any?
|
123
|
+
# Convert all additional paths to string
|
124
|
+
additional_paths = additional_paths.map do |path|
|
125
|
+
# We need to escape each path in case it contains caracters that
|
126
|
+
# are not appropriate to use as part of an URL.
|
127
|
+
# Unescape and then escape again in case the path is already escaped
|
128
|
+
URI::escape(URI::unescape(path.to_s))
|
129
|
+
end
|
130
|
+
uri = File.join(uri, *additional_paths)
|
131
|
+
end
|
132
|
+
uri
|
133
|
+
end
|
134
|
+
|
135
|
+
# Used when posting
|
136
|
+
# The access_token at this time seems to only work as GET parameter
|
137
|
+
def resource_uri_with_token(access_token, *additional_paths)
|
138
|
+
resource_uri(*additional_paths) + "?access_token=#{access_token}"
|
139
|
+
end
|
100
140
|
end
|
101
141
|
|
102
142
|
# Set default headers for OAuth authentication
|
@@ -104,7 +144,8 @@ module VerticalResponse
|
|
104
144
|
|
105
145
|
attr_accessor :response
|
106
146
|
|
107
|
-
def initialize(response)
|
147
|
+
def initialize(response, access_token = nil)
|
148
|
+
@access_token = access_token
|
108
149
|
self.response = response
|
109
150
|
end
|
110
151
|
end
|
@@ -13,13 +13,19 @@ module VerticalResponse
|
|
13
13
|
module API
|
14
14
|
class Contact < Resource
|
15
15
|
class << self
|
16
|
-
|
17
|
-
|
18
|
-
@base_uri ||= File.join(super.to_s, 'contacts')
|
16
|
+
def resource_uri_suffix
|
17
|
+
['contacts']
|
19
18
|
end
|
20
19
|
|
21
20
|
def fields(options = {})
|
22
|
-
Response.new get(resource_uri('fields'), build_query_params(options))
|
21
|
+
Response.new get(resource_uri('fields'), build_query_params(options), options[:access_token])
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_by_email(options = {})
|
25
|
+
validate_supported_method!(:find)
|
26
|
+
response = Response.new(get(resource_uri,build_query_params(options)), options[:access_token])
|
27
|
+
|
28
|
+
object_collection(response, options[:access_token])
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
@@ -31,13 +37,16 @@ module VerticalResponse
|
|
31
37
|
|
32
38
|
# Returns all the lists this contact belongs to
|
33
39
|
def lists(options = {})
|
40
|
+
options.merge!(access_token: @access_token)
|
34
41
|
@list_class.all(options)
|
35
42
|
end
|
36
43
|
|
37
44
|
# Returns all the messages targetted to the current contact
|
38
45
|
def messages(options = {})
|
46
|
+
options.merge!(access_token: @access_token)
|
39
47
|
@message_class.all(options)
|
40
48
|
end
|
41
49
|
end
|
50
|
+
|
42
51
|
end
|
43
52
|
end
|
@@ -12,9 +12,8 @@ module VerticalResponse
|
|
12
12
|
module API
|
13
13
|
class CustomField < Resource
|
14
14
|
class << self
|
15
|
-
|
16
|
-
|
17
|
-
@base_uri ||= File.join(super.to_s, 'custom_fields')
|
15
|
+
def resource_uri_suffix
|
16
|
+
['custom_fields']
|
18
17
|
end
|
19
18
|
|
20
19
|
def id_regexp
|
@@ -13,9 +13,8 @@ module VerticalResponse
|
|
13
13
|
module API
|
14
14
|
class Email < Resource
|
15
15
|
class << self
|
16
|
-
|
17
|
-
|
18
|
-
@base_uri ||= File.join(super.to_s, 'messages', 'emails')
|
16
|
+
def resource_uri_suffix
|
17
|
+
['messages', 'emails']
|
19
18
|
end
|
20
19
|
|
21
20
|
# Overwrite from parent class since it's a special type of
|
File without changes
|
@@ -12,9 +12,8 @@ module VerticalResponse
|
|
12
12
|
module API
|
13
13
|
class List < Resource
|
14
14
|
class << self
|
15
|
-
|
16
|
-
|
17
|
-
@base_uri ||= File.join(super.to_s, 'lists')
|
15
|
+
def resource_uri_suffix
|
16
|
+
['lists']
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -26,27 +25,37 @@ module VerticalResponse
|
|
26
25
|
|
27
26
|
# Returns all the messages targetted to the current list
|
28
27
|
def messages(options = {})
|
29
|
-
@
|
28
|
+
@access_token ||= options[:access_token]
|
29
|
+
@message_class.all(options.merge(access_token: @access_token))
|
30
30
|
end
|
31
31
|
|
32
32
|
# Returns all the contacts that belong to the list
|
33
33
|
def contacts(options = {})
|
34
|
-
@
|
34
|
+
@access_token ||= options[:access_token]
|
35
|
+
@contact_class.all(options.merge(access_token: @access_token))
|
35
36
|
end
|
36
37
|
|
37
38
|
def find_contact(contact_id, options = {})
|
38
|
-
@
|
39
|
+
@access_token ||= options[:access_token]
|
40
|
+
@contact_class.find(contact_id, options.merge(access_token: @access_token))
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_contact_by_email(email, options = {})
|
44
|
+
@access_token ||= options[:access_token]
|
45
|
+
@contact_class.find_by_email(options.merge(access_token: @access_token, email_address: email))
|
39
46
|
end
|
40
47
|
|
41
48
|
# Creates a contact for the list with the parameters provided
|
42
49
|
def create_contact(params)
|
43
|
-
@
|
50
|
+
@access_token ||= params[:access_token]
|
51
|
+
@contact_class.create(params.merge(access_token: @access_token))
|
44
52
|
end
|
45
53
|
|
46
54
|
# Creates contacts in batch for the list with the parameters provided
|
47
55
|
def create_contacts(params)
|
56
|
+
@access_token ||= params[:access_token]
|
48
57
|
params = { :contacts => params } if params.is_a?(Array)
|
49
|
-
@contact_class.create(params)
|
58
|
+
@contact_class.create(params.merge(access_token: @access_token))
|
50
59
|
end
|
51
60
|
|
52
61
|
# Deletes a contact from the list
|
@@ -57,7 +66,7 @@ module VerticalResponse
|
|
57
66
|
contact_to_delete.delete
|
58
67
|
end
|
59
68
|
|
60
|
-
# Deletes contacts in batch from the
|
69
|
+
# Deletes contacts in batch from the lists
|
61
70
|
def delete_contacts(contact_emails)
|
62
71
|
Response.new @contact_class.delete(
|
63
72
|
@contact_class.resource_uri,
|
@@ -14,8 +14,8 @@ module VerticalResponse
|
|
14
14
|
class Message < Resource
|
15
15
|
class << self
|
16
16
|
# Base URI for the Message resource
|
17
|
-
def
|
18
|
-
|
17
|
+
def resource_uri_suffix
|
18
|
+
['messages']
|
19
19
|
end
|
20
20
|
|
21
21
|
# Overwritting this method from the parent class since we want to
|
@@ -31,7 +31,7 @@ module VerticalResponse
|
|
31
31
|
message_class = SocialPost
|
32
32
|
end
|
33
33
|
end
|
34
|
-
message_class.new(response_item)
|
34
|
+
message_class.new(response_item, access_token)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# This class provides users the ability to generate oAuth tokens for the
|
2
|
+
# VerticalResponse API.
|
3
|
+
#
|
4
|
+
# Check the examples/sample code to know how to use this class.
|
5
|
+
|
6
|
+
require_relative 'client'
|
7
|
+
|
8
|
+
module VerticalResponse
|
9
|
+
module API
|
10
|
+
class OAuth < Client
|
11
|
+
# We expect HTML format as the API might redirect to a signin page or
|
12
|
+
# return errors in HTML format
|
13
|
+
format :html
|
14
|
+
|
15
|
+
def initialize(access_token)
|
16
|
+
@access_token = access_token
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
# Overwrite this method as we don't need to setup headers for
|
21
|
+
# OAuth calls
|
22
|
+
def assign_headers(*args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def resource_uri_suffix
|
26
|
+
['oauth']
|
27
|
+
end
|
28
|
+
|
29
|
+
# client_id is the application key
|
30
|
+
def authorize(client_id = "", redirect_uri = "")
|
31
|
+
get(
|
32
|
+
resource_uri('authorize'),
|
33
|
+
build_query_params({ :client_id => client_id, :redirect_uri => redirect_uri })
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def access_token(auth_code,
|
38
|
+
redirect_uri = "",
|
39
|
+
client_id = "",
|
40
|
+
client_secret = "")
|
41
|
+
get(
|
42
|
+
resource_uri('access_token'),
|
43
|
+
build_query_params({
|
44
|
+
:client_id => client_id,
|
45
|
+
:client_secret => client_secret,
|
46
|
+
:code => auth_code,
|
47
|
+
:redirect_uri => redirect_uri
|
48
|
+
})
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# ============================================================
|
54
|
+
# We want to access instances of OAuth with OOP, so we'll include
|
55
|
+
# some wrappers that let us use do the following:
|
56
|
+
# client = OAuth.new(access_token)
|
57
|
+
# client.lists
|
58
|
+
# client.contacts
|
59
|
+
#
|
60
|
+
# Please note, using static libraries isn't "object-oriented".
|
61
|
+
# Using instances is. The client in the example above is an
|
62
|
+
# example of an instance. This whole gem uses libraries
|
63
|
+
# instead of instances which is kindof bad.
|
64
|
+
#
|
65
|
+
# TODO: this whole gem should be more object-oriented, but for
|
66
|
+
# now this should work
|
67
|
+
# ============================================================
|
68
|
+
def lists(params = {})
|
69
|
+
params.merge!({access_token: @access_token})
|
70
|
+
VerticalResponse::API::List.all(params)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Afterwards, can use 'create_contact', etc.
|
74
|
+
def find_list(list_id, params = {})
|
75
|
+
params.merge!({access_token: @access_token})
|
76
|
+
VerticalResponse::API::List.find(list_id, params)
|
77
|
+
end
|
78
|
+
|
79
|
+
def contacts(params = {}, *path_prefix)
|
80
|
+
params.merge!({access_token: @access_token})
|
81
|
+
VerticalResponse::API::Contact.all(params, path_prefix)
|
82
|
+
end
|
83
|
+
|
84
|
+
def find_contact(contact_id, params = {})
|
85
|
+
params.merge!({access_token: @access_token})
|
86
|
+
VerticalResponse::API::Contact.find(contact_id, params)
|
87
|
+
end
|
88
|
+
|
89
|
+
def find_contact_by_email(email, params = {})
|
90
|
+
params.merge!({access_token: @access_token})
|
91
|
+
params.merge!({email_address: email})
|
92
|
+
VerticalResponse::API::Contact.find_by_email(params)
|
93
|
+
end
|
94
|
+
|
95
|
+
# One or more contacts; if creating more => custom fields aren't created remotely
|
96
|
+
# Attempt to create custom fields remotely => error
|
97
|
+
#
|
98
|
+
# For multiple, use contacts: [{...},{...}]
|
99
|
+
def create_contacts(contact_details, *path_prefix)
|
100
|
+
contact_details = { contacts: contact_details } if contact_details.is_a?(Array)
|
101
|
+
VerticalResponse::API::Contact.create(
|
102
|
+
contact_details.merge(access_token: @access_token),
|
103
|
+
path_prefix
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
def custom_fields(params = {})
|
108
|
+
params.merge!({access_token: @access_token})
|
109
|
+
VerticalResponse::API::CustomField.all(params)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -55,46 +55,56 @@ module VerticalResponse
|
|
55
55
|
url.match(/#{ resource_name }\/(#{ id_regexp })/)[1]
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
# Common
|
60
|
-
|
58
|
+
##################
|
59
|
+
# Common methods #
|
60
|
+
##################
|
61
61
|
|
62
62
|
# Returns a collection of current class objects.
|
63
63
|
# Useful for when we need to have an object oriented way to
|
64
64
|
# handle a list of items from an API response
|
65
|
-
def object_collection(response)
|
65
|
+
def object_collection(response, access_token = nil)
|
66
66
|
response.handle_collection do |response_item|
|
67
|
-
self.new(response_item)
|
67
|
+
self.new(response_item, access_token)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
# Returns all the objects of the current class
|
72
|
-
|
72
|
+
# The prefix is more or less a hack, to allow viewing contacts inside lists
|
73
|
+
# with one call
|
74
|
+
def all(options = {}, path_prefix = [])
|
73
75
|
validate_supported_method!(:all)
|
74
76
|
|
75
|
-
|
77
|
+
uri = resource_uri_with_prefix(path_prefix)
|
78
|
+
response = Response.new(get(uri, build_query_params(options)), options[:access_token])
|
76
79
|
|
77
|
-
object_collection(response)
|
80
|
+
object_collection(response, options[:access_token])
|
78
81
|
end
|
79
82
|
|
80
83
|
# Find and return an object of the current class based on its ID
|
81
84
|
def find(id, options = {})
|
82
85
|
validate_supported_method!(:find)
|
86
|
+
response = Response.new(get(resource_uri(id),build_query_params(options)))
|
83
87
|
|
84
|
-
|
85
|
-
|
86
|
-
self.new(response)
|
88
|
+
self.new(response, options[:access_token])
|
87
89
|
end
|
88
90
|
|
89
91
|
# Creates a new object of the current class with the parameters provided
|
90
|
-
def create(params)
|
92
|
+
def create(params, path_prefix = [])
|
93
|
+
access_token = params[:access_token]
|
94
|
+
params.delete :access_token
|
95
|
+
|
91
96
|
validate_supported_method!(:create)
|
92
97
|
|
93
|
-
|
94
|
-
|
95
|
-
|
98
|
+
uri = resource_uri_with_prefix(path_prefix)
|
99
|
+
|
100
|
+
# VerticalResponse doesn't like it when we pass the access_token via POST
|
101
|
+
uri += (uri.include? "?") ? "&" : "?"
|
102
|
+
uri += "access_token=#{access_token}"
|
103
|
+
|
104
|
+
response = Response.new(
|
105
|
+
post(uri, build_params(params))
|
96
106
|
)
|
97
|
-
self.new(response)
|
107
|
+
self.new(response, access_token)
|
98
108
|
end
|
99
109
|
end
|
100
110
|
|
@@ -117,21 +127,29 @@ module VerticalResponse
|
|
117
127
|
end
|
118
128
|
|
119
129
|
def update(params)
|
130
|
+
@access_token = params[:access_token]
|
131
|
+
params.delete :access_token
|
120
132
|
self.class.validate_supported_method!(:update)
|
121
133
|
|
122
|
-
response = Response.new
|
123
|
-
self.class.
|
124
|
-
|
134
|
+
response = Response.new(
|
135
|
+
self.class.put(
|
136
|
+
self.class.resource_uri_with_token(@access_token, id),
|
137
|
+
self.class.build_params(params)
|
138
|
+
)
|
125
139
|
)
|
126
|
-
self.class.new(response)
|
140
|
+
self.class.new(response, @access_token)
|
127
141
|
end
|
128
142
|
|
129
143
|
def delete(params = {})
|
144
|
+
@access_token = params[:access_token]
|
145
|
+
params.delete :access_token
|
130
146
|
self.class.validate_supported_method!(:delete)
|
131
147
|
|
132
|
-
Response.new
|
133
|
-
self.class.
|
134
|
-
|
148
|
+
Response.new(
|
149
|
+
self.class.delete(
|
150
|
+
self.class.resource_uri_with_token(@access_token, id),
|
151
|
+
self.class.build_params(params)
|
152
|
+
)
|
135
153
|
)
|
136
154
|
end
|
137
155
|
|
@@ -145,7 +163,9 @@ module VerticalResponse
|
|
145
163
|
uri = self.class.resource_uri(id, 'stats')
|
146
164
|
end
|
147
165
|
|
148
|
-
Response.new
|
166
|
+
Response.new(
|
167
|
+
self.class.get(uri, self.class.build_query_params(options))
|
168
|
+
)
|
149
169
|
end
|
150
170
|
end
|
151
171
|
end
|
@@ -6,9 +6,10 @@ require_relative 'error'
|
|
6
6
|
module VerticalResponse
|
7
7
|
module API
|
8
8
|
class Response
|
9
|
-
attr_reader :url, :items, :attributes, :links, :success, :error,
|
9
|
+
attr_reader :url, :items, :attributes, :links, :success, :error,
|
10
|
+
:raw_response, :access_token
|
10
11
|
|
11
|
-
def initialize(response)
|
12
|
+
def initialize(response, access_token = nil)
|
12
13
|
@url = response['url']
|
13
14
|
@items = response['items']
|
14
15
|
@attributes = response['attributes']
|
@@ -17,6 +18,8 @@ module VerticalResponse
|
|
17
18
|
@error = response['error']
|
18
19
|
@raw_response = response
|
19
20
|
|
21
|
+
@access_token = access_token
|
22
|
+
|
20
23
|
handle_error unless success?
|
21
24
|
end
|
22
25
|
|
@@ -24,7 +27,7 @@ module VerticalResponse
|
|
24
27
|
# for each one of them
|
25
28
|
def handle_collection
|
26
29
|
items.map do |item|
|
27
|
-
yield(Response.new(item))
|
30
|
+
yield(Response.new(item, @access_token))
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
@@ -13,9 +13,8 @@ module VerticalResponse
|
|
13
13
|
module API
|
14
14
|
class SocialPost < Resource
|
15
15
|
class << self
|
16
|
-
|
17
|
-
|
18
|
-
@base_uri ||= File.join(super.to_s, 'messages', 'social_posts')
|
16
|
+
def resource_uri_suffix
|
17
|
+
['messages', 'social_posts']
|
19
18
|
end
|
20
19
|
|
21
20
|
# Overwrite from parent class since it's a special type of
|
metadata
CHANGED
@@ -1,42 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verticalresponse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Cosmin Atanasiu
|
7
8
|
- Sridhar Devulkar
|
8
9
|
- Esteban Munoz
|
9
|
-
- Cosmin Atanasiu
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
date: 2014-06-18 00:00:00.000000000 Z
|
14
|
-
dependencies:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.3'
|
15
29
|
description: 'Gem used to connect to VerticalResponse.com''s API '
|
16
30
|
email:
|
31
|
+
- innorogue@gmail.com
|
17
32
|
- sdevulkar@verticalresponse.com
|
18
33
|
- emunoz@verticalresponse.com
|
19
|
-
- innorogue@gmail.com
|
20
34
|
executables: []
|
21
35
|
extensions: []
|
22
36
|
extra_rdoc_files:
|
23
37
|
- LICENSE
|
24
38
|
- README.md
|
25
39
|
files:
|
40
|
+
- lib/verticalresponse.rb
|
41
|
+
- lib/verticalresponse/api/oauth.rb
|
42
|
+
- lib/verticalresponse/api/client.rb
|
43
|
+
- lib/verticalresponse/api/custom_field.rb
|
44
|
+
- lib/verticalresponse/api/error.rb
|
45
|
+
- lib/verticalresponse/api/message.rb
|
46
|
+
- lib/verticalresponse/api/resource.rb
|
47
|
+
- lib/verticalresponse/api/social_post.rb
|
48
|
+
- lib/verticalresponse/api/contact.rb
|
49
|
+
- lib/verticalresponse/api/email.rb
|
50
|
+
- lib/verticalresponse/api/list.rb
|
51
|
+
- lib/verticalresponse/api/response.rb
|
26
52
|
- LICENSE
|
27
53
|
- README.md
|
28
|
-
- lib/client.rb
|
29
|
-
- lib/contact.rb
|
30
|
-
- lib/custom_field.rb
|
31
|
-
- lib/email.rb
|
32
|
-
- lib/error.rb
|
33
|
-
- lib/list.rb
|
34
|
-
- lib/message.rb
|
35
|
-
- lib/oauth.rb
|
36
|
-
- lib/resource.rb
|
37
|
-
- lib/response.rb
|
38
|
-
- lib/social_post.rb
|
39
|
-
- lib/verticalresponse.rb
|
40
54
|
homepage:
|
41
55
|
licenses:
|
42
56
|
- GPLv3
|
@@ -57,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
71
|
version: '0'
|
58
72
|
requirements: []
|
59
73
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.
|
74
|
+
rubygems_version: 2.1.11
|
61
75
|
signing_key:
|
62
76
|
specification_version: 4
|
63
77
|
summary: Gem used to connect to VerticalResponse.com's API
|
data/lib/oauth.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# This class provides users the ability to generate oAuth tokens for the
|
2
|
-
# VerticalResponse API.
|
3
|
-
#
|
4
|
-
# Check the examples/sample code to know how to use this class.
|
5
|
-
|
6
|
-
require_relative 'client'
|
7
|
-
|
8
|
-
module VerticalResponse
|
9
|
-
module API
|
10
|
-
class OAuth < Client
|
11
|
-
# We expect HTML format as the API might redirect to a signin page or
|
12
|
-
# return errors in HTML format
|
13
|
-
format :html
|
14
|
-
|
15
|
-
def initialize(access_token)
|
16
|
-
@access_token = access_token
|
17
|
-
end
|
18
|
-
|
19
|
-
def lists
|
20
|
-
VerticalResponse::API::List.all({"access_token" => @access_token})
|
21
|
-
end
|
22
|
-
|
23
|
-
def contacts
|
24
|
-
VerticalResponse::API::Contact.all({"access_token" => @access_token})
|
25
|
-
end
|
26
|
-
|
27
|
-
def get_list(list_id)
|
28
|
-
VerticalResponse::API::List.find(list_id, {"access_token" => @access_token})
|
29
|
-
end
|
30
|
-
|
31
|
-
class << self
|
32
|
-
# Overwrite this method as we don't need to setup headers for
|
33
|
-
# OAuth calls
|
34
|
-
def assign_headers(*args)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Base URI for the OAuth calls
|
38
|
-
def base_uri(*args)
|
39
|
-
@base_uri ||= File.join(super.to_s, 'oauth')
|
40
|
-
end
|
41
|
-
|
42
|
-
# client_id is the application key
|
43
|
-
def authorize(redirect_uri = "", client_id = "")
|
44
|
-
get(
|
45
|
-
resource_uri('authorize'),
|
46
|
-
build_query_params({ :client_id => client_id, :redirect_uri => redirect_uri })
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
def access_token(auth_code,
|
51
|
-
redirect_uri = "",
|
52
|
-
client_id = "",
|
53
|
-
client_secret = "")
|
54
|
-
get(
|
55
|
-
resource_uri('access_token'),
|
56
|
-
build_query_params({
|
57
|
-
:client_id => client_id,
|
58
|
-
:client_secret => client_secret,
|
59
|
-
:code => auth_code,
|
60
|
-
:redirect_uri => redirect_uri
|
61
|
-
})
|
62
|
-
)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|