pomade 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/.yardopts +2 -0
- data/Gemfile +7 -1
- data/Rakefile +21 -1
- data/lib/pomade/exceptions.rb +3 -0
- data/lib/pomade/publisher.rb +205 -94
- data/lib/pomade/version.rb +1 -1
- data/readme.md +75 -30
- data/test/test_helper.rb +11 -0
- data/test/test_publisher.rb +22 -0
- metadata +15 -4
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
# ----- Utility Functions -----
|
5
|
+
|
6
|
+
def scope(path)
|
7
|
+
File.join(File.dirname(__FILE__), path)
|
8
|
+
end
|
9
|
+
|
10
|
+
# ----- Default: Testing -----
|
11
|
+
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
require 'rake/testtask'
|
15
|
+
|
16
|
+
Rake::TestTask.new do |t|
|
17
|
+
t.libs << 'test'
|
18
|
+
test_files = FileList[scope('test/test_*.rb')]
|
19
|
+
t.test_files = test_files
|
20
|
+
t.verbose = true
|
21
|
+
end
|
data/lib/pomade/exceptions.rb
CHANGED
data/lib/pomade/publisher.rb
CHANGED
@@ -7,88 +7,164 @@ module Pomade
|
|
7
7
|
# Handles all interactions to Pomegranate.
|
8
8
|
class Publisher
|
9
9
|
##
|
10
|
-
# Creates a new instance of
|
10
|
+
# Creates a new instance of `Publisher` that pushes records to Pomegranate. If you do not set any optional arguments, Pomade will connect to Pomegranate's public sandbox instance.
|
11
11
|
#
|
12
|
-
#
|
12
|
+
# ## Parameters
|
13
13
|
#
|
14
|
-
# *
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# *
|
20
|
-
# *
|
21
|
-
# *
|
22
|
-
# *
|
14
|
+
# * **args** _(hash, optional)_
|
15
|
+
# * **:subdomain** _(string)_ -- The subdomain for the Pomegranate instance that you'd like to connect to.
|
16
|
+
# * **:username** _(string)_ -- The username used for connecting to your isntance.
|
17
|
+
# * **:password** _(string)_ -- The password used for connecting to your isntance.
|
18
|
+
# * **:client_id** _(string)_ -- Your client ID.
|
19
|
+
# * **:skip_authentication** _(string)_ -- Skip any authentication tests
|
20
|
+
# * **:host** _(string)_ -- The host (domain name) that your Pomegranate instance lives on.
|
21
|
+
# * **:pathname** _(string)_ -- The path that is used for interacting with assets.
|
22
|
+
# * **:time_format** _(strftime)_ -- Change the layout of the timestamp that is posted to your instance.
|
23
|
+
# * **:domain** _(string)_ -- NTLM login domain.
|
23
24
|
#
|
24
|
-
#
|
25
|
-
# An instance of +Pomade::Publisher+
|
25
|
+
# ## Returns
|
26
26
|
#
|
27
|
-
#
|
27
|
+
# An instance of `Pomade::Publisher`
|
28
|
+
#
|
29
|
+
# ## Example
|
28
30
|
#
|
29
|
-
#
|
30
|
-
def initialize(
|
31
|
-
@subdomain = subdomain
|
32
|
-
@username = username
|
33
|
-
@password = password
|
34
|
-
@client_id = client_id
|
31
|
+
# @pom = Pomade::Publisher.new('my-subdomain', 'myusername', 'mypassword', 'XX')
|
32
|
+
def initialize(args = {})
|
33
|
+
@subdomain = args[:subdomain] || 'pomegranate'
|
34
|
+
@username = args[:username] || nil
|
35
|
+
@password = args[:password] || nil
|
36
|
+
@client_id = args[:client_id] || 'P0'
|
35
37
|
|
36
38
|
# Other options
|
37
39
|
@options = {}
|
38
|
-
@options[:
|
39
|
-
@options[:
|
40
|
-
@options[:
|
41
|
-
@options[:
|
40
|
+
@options[:skip_authentication] = args[:skip_authentication] || false
|
41
|
+
@options[:host] = args[:host] || 'timessquare2.com'
|
42
|
+
@options[:pathname] = args[:pathname] || '/p/p.svc/Assets/'
|
43
|
+
@options[:time_format] = args[:time_format] || "%Y-%m-%dT%H:%M:%SZ"
|
44
|
+
@options[:domain] = args[:domain] || nil
|
45
|
+
|
46
|
+
# Test authentication
|
47
|
+
test_authentication! unless @options[:skip_authentication]
|
42
48
|
end
|
43
49
|
|
44
50
|
##
|
45
|
-
#
|
51
|
+
# Sets authentication credentials
|
52
|
+
#
|
53
|
+
# ## Parameters
|
46
54
|
#
|
47
|
-
#
|
55
|
+
# * **credentials** _(hash)_
|
56
|
+
# * **:subdomain** _(string)_ -- The subdomain for the Pomegranate instance that you'd like to connect to.
|
57
|
+
# * **:username** _(string)_ -- The username used for connecting to your isntance.
|
58
|
+
# * **:password** _(string)_ -- The password used for connecting to your isntance.
|
59
|
+
# * **:client_id** _(string)_ -- Your client ID.
|
60
|
+
#
|
61
|
+
# ## Returns
|
48
62
|
#
|
49
|
-
#
|
50
|
-
# * +:image+ -- An +IMAGE+ type asset
|
51
|
-
# * +:video+ -- A +VIDEO+ type asset
|
52
|
-
# * +:text+ -- A +TEXT+ type asset
|
63
|
+
# A `boolean` depending on whether the authentication passed or failed.
|
53
64
|
#
|
54
|
-
#
|
65
|
+
# ## Example
|
55
66
|
#
|
56
|
-
#
|
67
|
+
# credz = {
|
68
|
+
# username: "myuser",
|
69
|
+
# password: "mypass",
|
70
|
+
# subdomain: "mysubdomain",
|
71
|
+
# client_id: "XX"
|
72
|
+
# }
|
73
|
+
# @pom.authenticate(opts)
|
74
|
+
# # => true
|
75
|
+
def authenticate(credentials)
|
76
|
+
@subdomain = credentials[:subdomain] || @subdomain
|
77
|
+
@username = credentials[:username] || @username
|
78
|
+
@password = credentials[:password] || @password
|
79
|
+
@client_id = credentials[:client_id] || @client_id
|
80
|
+
|
81
|
+
test_authentication unless @options[:skip_authentication]
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Check if authentication is set
|
86
|
+
def authentication_set?
|
87
|
+
!@username.nil? && !@password.nil?
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Performs a GET request on the Pomegranate instance's feed to ensure login credentials are correct.
|
92
|
+
def test_authentication
|
93
|
+
status = false
|
94
|
+
|
95
|
+
Net::HTTP.start("#{@subdomain}.#{@options[:host]}", 80) do |http|
|
96
|
+
req = Net::HTTP::Get.new(@options[:pathname])
|
97
|
+
|
98
|
+
if authentication_set?
|
99
|
+
req.ntlm_auth(@username, @options[:domain], @password)
|
100
|
+
end
|
101
|
+
|
102
|
+
response = http.request(req)
|
103
|
+
|
104
|
+
if response.code.to_i.between?(200,399)
|
105
|
+
status = true
|
106
|
+
else
|
107
|
+
status = false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
return status
|
112
|
+
end
|
113
|
+
|
114
|
+
##
|
115
|
+
# Raises AuthenticationError if authentication fails
|
116
|
+
def test_authentication!
|
117
|
+
raise AuthenticationError unless test_authentication
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Publishes an array of assets to Pomegranate and returns the results in a `hash`.
|
122
|
+
#
|
123
|
+
# ## Parameters
|
124
|
+
#
|
125
|
+
# * **assets** _(array)_ -- A collection of assets. Each item consists of a hash with three keys: `:target`, `:type` and `:value`. The values for keys `:target` and `:value` are both strings while the `:type` key's value is a symbol. Available values are:
|
126
|
+
# * `:image` -- An `IMAGE type asset
|
127
|
+
# * `:video` -- A `VIDEO` type asset
|
128
|
+
# * `:text` -- A `TEXT` type asset
|
57
129
|
#
|
58
|
-
#
|
130
|
+
# ## Returns
|
59
131
|
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# {
|
68
|
-
# record_id: "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
|
69
|
-
# assets: [
|
70
|
-
# {
|
71
|
-
# "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
|
72
|
-
# "AssetData" => "jakebellacera",
|
73
|
-
# "AssetType" => "TEXT",
|
74
|
-
# "Target" => "XX~username",
|
75
|
-
# "Client" => "XX",
|
76
|
-
# "Status" => "APPROVED",
|
77
|
-
# "AssetMeta" => "",
|
78
|
-
# "AssetRecordID" => "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
|
79
|
-
# },
|
80
|
-
# {
|
81
|
-
# "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
|
82
|
-
# "AssetData" => "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png",
|
83
|
-
# "AssetType" => "IMAGE",
|
84
|
-
# "Target" => "XX~avatar",
|
85
|
-
# "Client" => "XX",
|
86
|
-
# "Status" => "APPROVED",
|
87
|
-
# "AssetMeta" => "",
|
88
|
-
# "AssetRecordID" => "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
|
89
|
-
# }
|
132
|
+
# A `hash` containing two keys: `record_id` and `assets`.
|
133
|
+
#
|
134
|
+
# ## Example
|
135
|
+
#
|
136
|
+
# assets = [
|
137
|
+
# { target: "PUB~1text", type: :text, value: "jakebellacera" },
|
138
|
+
# { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
|
90
139
|
# ]
|
91
|
-
#
|
140
|
+
#
|
141
|
+
# @pom.publish(records)
|
142
|
+
# # =>
|
143
|
+
# {
|
144
|
+
# record_id: "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
|
145
|
+
# assets: [
|
146
|
+
# {
|
147
|
+
# "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
|
148
|
+
# "AssetData" => "jakebellacera",
|
149
|
+
# "AssetType" => "TEXT",
|
150
|
+
# "Target" => "PUB~1text",
|
151
|
+
# "Client" => "P0",
|
152
|
+
# "Status" => "UPLOADED",
|
153
|
+
# "AssetMeta" => "",
|
154
|
+
# "AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
|
155
|
+
# },
|
156
|
+
# {
|
157
|
+
# "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476c",
|
158
|
+
# "AssetData" => "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png",
|
159
|
+
# "AssetType" => "IMAGE",
|
160
|
+
# "Target" => "PUB~1image",
|
161
|
+
# "Client" => "P0",
|
162
|
+
# "Status" => "UPLOADED",
|
163
|
+
# "AssetMeta" => "",
|
164
|
+
# "AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
|
165
|
+
# }
|
166
|
+
# ]
|
167
|
+
# }
|
92
168
|
def publish(assets)
|
93
169
|
@record_id = generate_record_id
|
94
170
|
@time = Time.now.strftime(@options[:time_format])
|
@@ -108,30 +184,30 @@ module Pomade
|
|
108
184
|
##
|
109
185
|
# Validates an array of assets.
|
110
186
|
#
|
111
|
-
#
|
187
|
+
# ## Parameters
|
112
188
|
#
|
113
|
-
# *
|
114
|
-
# *
|
115
|
-
# *
|
116
|
-
# *
|
189
|
+
# * **assets** _(array)_ -- A collection of assets. Each item consists of a hash with three keys: `:target`, `:type` and `:value`. The values for keys `:target` and `:value` are both strings while the `:type` key's value is a symbol. Available values are:
|
190
|
+
# * `:image` -- An `IMAGE` type asset
|
191
|
+
# * `:video` -- A `VIDEO` type asset
|
192
|
+
# * `:text` -- A `TEXT` type asset
|
117
193
|
#
|
118
|
-
#
|
194
|
+
# ## Returns
|
119
195
|
#
|
120
|
-
# The
|
196
|
+
# The `array` of assets.
|
121
197
|
#
|
122
|
-
#
|
198
|
+
# ## Example
|
123
199
|
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
200
|
+
# assets = [
|
201
|
+
# { target: "PUB~1text", type: :text, value: "jakebellacera" },
|
202
|
+
# { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
|
203
|
+
# ]
|
204
|
+
#
|
205
|
+
# @pom.validate(records)
|
206
|
+
# # =>
|
207
|
+
# [
|
208
|
+
# { target: "PUB~1text", type: :text, value: "jakebellacera" },
|
209
|
+
# { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
|
210
|
+
# ]
|
135
211
|
def validate(assets)
|
136
212
|
available_keys = [:target, :type, :value].sort
|
137
213
|
|
@@ -142,16 +218,48 @@ module Pomade
|
|
142
218
|
end
|
143
219
|
end
|
144
220
|
|
221
|
+
##
|
222
|
+
# Checks if the assets are valid or not.
|
223
|
+
#
|
224
|
+
# ## Parameters
|
225
|
+
#
|
226
|
+
# * **assets** _(array)_ -- A collection of assets. Each item consists of a hash with three keys: `:target`, `:type` and `:value`. The values for keys `:target` and `:value` are both strings while the `:type` key's value is a symbol. Available values are:
|
227
|
+
# * `:image` -- An `IMAGE` type asset
|
228
|
+
# * `:video` -- A `VIDEO` type asset
|
229
|
+
# * `:text` -- A `TEXT` type asset
|
230
|
+
#
|
231
|
+
# ## Returns
|
232
|
+
#
|
233
|
+
# A `boolean` depending on if the assets pass or fail validation.
|
234
|
+
#
|
235
|
+
# ## Example
|
236
|
+
#
|
237
|
+
# assets = [
|
238
|
+
# { target: "PUB~1text", type: :text, value: "jakebellacera" },
|
239
|
+
# { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
|
240
|
+
# ]
|
241
|
+
#
|
242
|
+
# @pom.valid?(records)
|
243
|
+
# # => true
|
244
|
+
def valid?(assets)
|
245
|
+
begin
|
246
|
+
validate(assets)
|
247
|
+
return true
|
248
|
+
rescue
|
249
|
+
return false
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
145
253
|
private
|
146
254
|
|
147
255
|
##
|
148
|
-
# Generates a
|
256
|
+
# Generates a `SecureRandom.uuid` (GUID) with the `client_id` appended to it.
|
149
257
|
def generate_record_id
|
150
258
|
@client_id + '-' + SecureRandom.uuid
|
151
259
|
end
|
152
260
|
|
153
261
|
##
|
154
|
-
# Tests to see if an asset's
|
262
|
+
# Tests to see if an asset's `:value` is correct in correlation to its `:type`.
|
155
263
|
def test(asset)
|
156
264
|
# If the value is a URL...
|
157
265
|
if (asset[:type] == :image || asset[:type] == :video) && url?(asset[:value])
|
@@ -166,15 +274,15 @@ module Pomade
|
|
166
274
|
##
|
167
275
|
# Posts an XML to the Pomegranate instance and handles the response.
|
168
276
|
#
|
169
|
-
#
|
277
|
+
# **Note:** This method will fail if any requests are rejected.
|
170
278
|
#
|
171
|
-
#
|
279
|
+
# ## Parameters
|
172
280
|
#
|
173
|
-
# *
|
281
|
+
# * **body** _(string, XML)_ -- A Pomegranate XML asset
|
174
282
|
#
|
175
|
-
#
|
283
|
+
# ## Returns
|
176
284
|
#
|
177
|
-
# An
|
285
|
+
# An `array` of comiled Pomegranate assets
|
178
286
|
def post(data)
|
179
287
|
response_data = []
|
180
288
|
data.each do |xml|
|
@@ -201,9 +309,9 @@ module Pomade
|
|
201
309
|
##
|
202
310
|
# Sends a request to Pomegranate
|
203
311
|
#
|
204
|
-
#
|
312
|
+
# ## Parameters
|
205
313
|
#
|
206
|
-
# * *body* _(string, XML)_
|
314
|
+
# * *body* _(string, XML)_ -- A Pomegranate XML asset
|
207
315
|
def send_request(body)
|
208
316
|
status = false
|
209
317
|
data = false
|
@@ -215,7 +323,10 @@ module Pomade
|
|
215
323
|
req.content_type = 'application/atom+xml'
|
216
324
|
req.content_length = body.size - 20 # Currently a bug with the Pomegranate API I believe
|
217
325
|
req.body = body
|
218
|
-
|
326
|
+
|
327
|
+
if authentication_set?
|
328
|
+
req.ntlm_auth(@username, @options[:domain], @password)
|
329
|
+
end
|
219
330
|
|
220
331
|
response = http.request(req)
|
221
332
|
|
@@ -255,7 +366,7 @@ module Pomade
|
|
255
366
|
<d:AssetRecordID>#{@record_id}</d:AssetRecordID>
|
256
367
|
<d:Target>#{target}</d:Target>
|
257
368
|
<d:Client>#{@client_id}</d:Client>
|
258
|
-
<d:Status
|
369
|
+
<d:Status>#{@client_id == "P0" ? "UPLOADED" : "APPROVED"}</d:Status>
|
259
370
|
</m:properties>
|
260
371
|
</content>
|
261
372
|
</entry>
|
data/lib/pomade/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Pomade - The ruby Pomegranate API wrapper
|
2
2
|
|
3
|
-
Pomade is a
|
3
|
+
Pomade is a ruby library that acts as an API wrapper used for interfacing with TimesSquare2's [Pomegranate API](http://api.timessquare2.com/pomegranate/).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'pomade'
|
9
|
+
gem 'pomade', '~> 0.2.2'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -18,79 +18,124 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Publisher
|
20
20
|
|
21
|
-
|
21
|
+
_View the full documentation [here](http://rdoc.info/github/jakebellacera/pomade/master/Pomade/Publisher)_
|
22
|
+
|
23
|
+
Publisher lets you easily publish content to the Pomegranate API. It handles everything from authenticating your requests to building XML files, so all you need to worry about is the content.
|
22
24
|
|
23
25
|
```ruby
|
24
|
-
Pomade::Publisher.new
|
25
|
-
```
|
26
|
+
@pom = Pomade::Publisher.new
|
26
27
|
|
27
|
-
|
28
|
+
assets = [
|
29
|
+
{ target: "PUB~1text", type: :text, value: "jakebellacera" },
|
30
|
+
{ target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
|
31
|
+
]
|
28
32
|
|
29
|
-
|
33
|
+
record = @pom.publish(assets)
|
30
34
|
|
31
|
-
|
35
|
+
puts record
|
36
|
+
# =>
|
32
37
|
{
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
record_id: "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
|
39
|
+
assets: [
|
40
|
+
{
|
41
|
+
"AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
|
42
|
+
"AssetData" => "jakebellacera",
|
43
|
+
"AssetType" => "TEXT",
|
44
|
+
"Target" => "PUB~1text",
|
45
|
+
"Client" => "P0",
|
46
|
+
"Status" => "UPLOADED",
|
47
|
+
"AssetMeta" => "",
|
48
|
+
"AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
|
52
|
+
"AssetData" => "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png",
|
53
|
+
"AssetType" => "IMAGE",
|
54
|
+
"Target" => "PUB~1image",
|
55
|
+
"Client" => "P0",
|
56
|
+
"Status" => "UPLOADED",
|
57
|
+
"AssetMeta" => "",
|
58
|
+
"AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
|
59
|
+
}
|
60
|
+
]
|
37
61
|
}
|
38
62
|
```
|
39
63
|
|
40
64
|
### Usage
|
41
65
|
|
42
|
-
To publish assets to Pomegranate, simply create a new
|
66
|
+
To publish assets to Pomegranate, simply create a new Publisher instance (for available options, [go here](http://rdoc.info/github/jakebellacera/pomade/master/Pomade/Publisher:initialize)).
|
43
67
|
|
44
68
|
```ruby
|
45
|
-
@pom = Pomade::Publisher.new
|
69
|
+
@pom = Pomade::Publisher.new
|
46
70
|
```
|
47
71
|
|
48
|
-
Next, you'll
|
72
|
+
Next, you'll need to publish your assets. An asset is a `hash` that consists of three keys: **:target**, **:type** and **:value**.
|
49
73
|
|
50
74
|
```ruby
|
51
75
|
assets = [
|
52
|
-
{ target: "
|
53
|
-
{ target: "
|
76
|
+
{ target: "PUB~1text", type: :text, value: "jakebellacera" },
|
77
|
+
{ target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
|
54
78
|
]
|
55
79
|
|
56
80
|
record = @pom.publish(assets)
|
57
81
|
```
|
58
82
|
|
59
|
-
|
83
|
+
Once the publishing is complete, Publisher will return the finalized record data.
|
60
84
|
|
61
85
|
```ruby
|
62
86
|
puts record
|
63
|
-
|
87
|
+
# =>
|
64
88
|
{
|
65
|
-
record_id: "
|
89
|
+
record_id: "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
|
66
90
|
assets: [
|
67
91
|
{
|
68
92
|
"AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
|
69
93
|
"AssetData" => "jakebellacera",
|
70
94
|
"AssetType" => "TEXT",
|
71
|
-
"Target" => "
|
72
|
-
"Client" => "
|
73
|
-
"Status" => "
|
95
|
+
"Target" => "PUB~1text",
|
96
|
+
"Client" => "P0",
|
97
|
+
"Status" => "UPLOADED",
|
74
98
|
"AssetMeta" => "",
|
75
|
-
"AssetRecordID" => "
|
99
|
+
"AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
|
76
100
|
},
|
77
101
|
{
|
78
|
-
"AssetID" => "9a24c8e2-1066-42fb-be1c-
|
102
|
+
"AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476c",
|
79
103
|
"AssetData" => "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png",
|
80
104
|
"AssetType" => "IMAGE",
|
81
|
-
"Target" => "
|
82
|
-
"Client" => "
|
83
|
-
"Status" => "
|
105
|
+
"Target" => "PUB~1image",
|
106
|
+
"Client" => "P0",
|
107
|
+
"Status" => "UPLOADED",
|
84
108
|
"AssetMeta" => "",
|
85
|
-
"AssetRecordID" => "
|
109
|
+
"AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
|
86
110
|
}
|
87
111
|
]
|
88
112
|
}
|
89
113
|
```
|
90
114
|
|
115
|
+
#### Authentication
|
116
|
+
|
117
|
+
If you require authentication, you can authenticate either at initialization or by running the `authenticate` method. Publisher will attempt to authenticate with Pomegranate. Since this is a setter method, you can authenticate as many times as you'd like throughout your application.
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
credz = {
|
121
|
+
username: "myuser",
|
122
|
+
password: "mypass",
|
123
|
+
subdomain: "mysubdomain",
|
124
|
+
client_id: "XX"
|
125
|
+
}
|
126
|
+
@pom.authenticate(opts)
|
127
|
+
# => true
|
128
|
+
```
|
129
|
+
|
91
130
|
#### Validation
|
92
131
|
|
93
|
-
Once you attempt to publish your assets,
|
132
|
+
Once you attempt to publish your assets, Publisher will attempt to validate your assets. Most of the time it will work, as Publisher will check your URLS if the asset's type is :image and :video and ensure that they resolve properly. This validation may not find everything and you'll still get a bad response from Pomegranate. If that's the case, please [file a bug](http://github.com/jakebellacera/pomade/issues) with the steps you took to reproduce the problem.
|
133
|
+
|
134
|
+
You can also run a validation manually by running the `validate(assets)` method where `assets` is your array of assets to check against.
|
135
|
+
|
136
|
+
## More Info
|
137
|
+
|
138
|
+
Need more info? Check the [docs](http://rdoc.info/github/jakebellacera/pomade/master/frames) or [browse the source](http://github.com/jakebellacera/pomade).
|
94
139
|
|
95
140
|
## Contributing
|
96
141
|
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup(:default, :test)
|
4
|
+
Bundler.require(:default, :test)
|
5
|
+
|
6
|
+
dir = File.dirname(File.expand_path(__FILE__))
|
7
|
+
$LOAD_PATH.unshift dir + '/../lib'
|
8
|
+
$TESTING = true
|
9
|
+
require 'test/unit'
|
10
|
+
require 'pomade'
|
11
|
+
require 'tzinfo'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Fixtures
|
4
|
+
$valid_assets = [
|
5
|
+
{ target: "XX~username", type: :text, value: "jakebellacera"},
|
6
|
+
{ target: "XX~avatar", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png"}
|
7
|
+
]
|
8
|
+
|
9
|
+
class PublisherTest < Test::Unit::TestCase
|
10
|
+
def test_public_authentication
|
11
|
+
pom = Pomade::Publisher.new
|
12
|
+
assert pom.test_authentication
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_asset_validation
|
16
|
+
pom = Pomade::Publisher.new
|
17
|
+
|
18
|
+
assert_nothing_raised do
|
19
|
+
pom.validate($valid_assets)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pomade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-ntlm
|
@@ -51,6 +51,8 @@ extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
53
|
- .gitignore
|
54
|
+
- .travis.yml
|
55
|
+
- .yardopts
|
54
56
|
- Gemfile
|
55
57
|
- LICENSE.txt
|
56
58
|
- Rakefile
|
@@ -60,6 +62,8 @@ files:
|
|
60
62
|
- lib/pomade/version.rb
|
61
63
|
- pomade.gemspec
|
62
64
|
- readme.md
|
65
|
+
- test/test_helper.rb
|
66
|
+
- test/test_publisher.rb
|
63
67
|
homepage: http://github.com/jakebellacera/pomade
|
64
68
|
licenses: []
|
65
69
|
post_install_message:
|
@@ -72,17 +76,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
76
|
- - ! '>='
|
73
77
|
- !ruby/object:Gem::Version
|
74
78
|
version: '0'
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
hash: 1927956313076339663
|
75
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
83
|
none: false
|
77
84
|
requirements:
|
78
85
|
- - ! '>='
|
79
86
|
- !ruby/object:Gem::Version
|
80
87
|
version: '0'
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
hash: 1927956313076339663
|
81
91
|
requirements: []
|
82
92
|
rubyforge_project:
|
83
93
|
rubygems_version: 1.8.24
|
84
94
|
signing_key:
|
85
95
|
specification_version: 3
|
86
96
|
summary: Ruby wrapper for TimesSquare2's Pomegranate API
|
87
|
-
test_files:
|
88
|
-
|
97
|
+
test_files:
|
98
|
+
- test/test_helper.rb
|
99
|
+
- test/test_publisher.rb
|