hark 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +50 -0
- data/README.md +307 -0
- data/Rakefile +43 -0
- data/hark.gemspec +29 -0
- data/lib/hark.rb +21 -0
- data/lib/hark/api.rb +78 -0
- data/lib/hark/configuration.rb +10 -0
- data/lib/hark/version.rb +3 -0
- data/test/fixtures/vcr_cassettes/existing-clip.yml +55 -0
- data/test/fixtures/vcr_cassettes/non-existent-clip.yml +44 -0
- data/test/test_hark.rb +10 -0
- data/test/test_hark_api.rb +78 -0
- data/test/test_hark_configuration.rb +32 -0
- data/test/test_hark_version.rb +9 -0
- data/test/test_helper.rb +37 -0
- metadata +177 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in hark-api.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'rake'
|
7
|
+
gem 'httparty'
|
8
|
+
gem 'activesupport'
|
9
|
+
|
10
|
+
group :development, :test do
|
11
|
+
gem 'mocha'
|
12
|
+
gem 'shoulda'
|
13
|
+
gem 'vcr'
|
14
|
+
gem 'webmock'
|
15
|
+
gem 'json'
|
16
|
+
gem 'rdoc'
|
17
|
+
gem 'yard'
|
18
|
+
gem 'rdiscount'
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hark (0.0.1)
|
5
|
+
activesupport
|
6
|
+
httparty
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (3.1.1)
|
12
|
+
multi_json (~> 1.0)
|
13
|
+
addressable (2.2.6)
|
14
|
+
crack (0.3.1)
|
15
|
+
httparty (0.8.1)
|
16
|
+
multi_json
|
17
|
+
multi_xml
|
18
|
+
json (1.6.1)
|
19
|
+
metaclass (0.0.1)
|
20
|
+
mocha (0.10.0)
|
21
|
+
metaclass (~> 0.0.1)
|
22
|
+
multi_json (1.0.3)
|
23
|
+
multi_xml (0.4.1)
|
24
|
+
rake (0.9.2.2)
|
25
|
+
rdiscount (1.6.8)
|
26
|
+
rdoc (3.11)
|
27
|
+
json (~> 1.4)
|
28
|
+
shoulda (2.11.3)
|
29
|
+
vcr (1.11.3)
|
30
|
+
webmock (1.7.7)
|
31
|
+
addressable (~> 2.2, > 2.2.5)
|
32
|
+
crack (>= 0.1.7)
|
33
|
+
yard (0.7.3)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
activesupport
|
40
|
+
hark!
|
41
|
+
httparty
|
42
|
+
json
|
43
|
+
mocha
|
44
|
+
rake
|
45
|
+
rdiscount
|
46
|
+
rdoc
|
47
|
+
shoulda
|
48
|
+
vcr
|
49
|
+
webmock
|
50
|
+
yard
|
data/README.md
ADDED
@@ -0,0 +1,307 @@
|
|
1
|
+
Hark API
|
2
|
+
========
|
3
|
+
|
4
|
+
A Ruby Gem to access the hark.com API
|
5
|
+
|
6
|
+
About Hark
|
7
|
+
----------
|
8
|
+
hark.com is a site that publishes movie quote sound bites and still images.
|
9
|
+
This gem is used to access these sounds :mega: , still images, and other
|
10
|
+
information in a programmatic fashion.
|
11
|
+
|
12
|
+
Reference
|
13
|
+
---------
|
14
|
+
|
15
|
+
### Pure HTTP Example
|
16
|
+
|
17
|
+
The Hark API is accessed through a HTTP GET focused REST interface currently
|
18
|
+
supporting JSON and JSONP formats. The API is currently version 1.0 and is only
|
19
|
+
accessible over HTTPS. The token to access the API is submitted as a HTTP
|
20
|
+
header with the name X-HarkToken.
|
21
|
+
|
22
|
+
#### JSON Access
|
23
|
+
|
24
|
+
```shell
|
25
|
+
curl --verbose -H "X-HarkToken: a-token" "https://api.hark.com/1.0/clips/jxxcfhxywx.json"
|
26
|
+
```
|
27
|
+
|
28
|
+
#### JSONP Access
|
29
|
+
|
30
|
+
The value of callback is the variable name that is returned wrapping the result
|
31
|
+
JSON.
|
32
|
+
|
33
|
+
```shell
|
34
|
+
curl --verbose -H "X-HarkToken: a-token" "https://api.hark.com/1.0/clips/jxxcfhxywx.json?callback=wrapper"
|
35
|
+
```
|
36
|
+
|
37
|
+
Formatting
|
38
|
+
----------
|
39
|
+
|
40
|
+
### API Information
|
41
|
+
|
42
|
+
All results return information about the request and its results.
|
43
|
+
|
44
|
+
* version - API Version.
|
45
|
+
* when - When these results returned.
|
46
|
+
* what - The kind of object requested, clip, clips, collection, collections, etc.
|
47
|
+
* message - A message about the request.
|
48
|
+
* status - The HTTP status given with the result.
|
49
|
+
|
50
|
+
|
51
|
+
### Error results
|
52
|
+
|
53
|
+
#### Missing query parameters
|
54
|
+
|
55
|
+
HTTP Status 400. Parameter(s) for the query were missing.
|
56
|
+
|
57
|
+
```json
|
58
|
+
{
|
59
|
+
"collections": [
|
60
|
+
|
61
|
+
],
|
62
|
+
"api": {
|
63
|
+
"version": "1.0.1",
|
64
|
+
"when": "Tue Nov 01 05:39:41 UTC 2011",
|
65
|
+
"what": "collections",
|
66
|
+
"message": "missing keywords query",
|
67
|
+
"status": 400
|
68
|
+
}
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Authorization Failure
|
73
|
+
|
74
|
+
HTTP Status 401. The API token given was not authorized.
|
75
|
+
|
76
|
+
```json
|
77
|
+
{
|
78
|
+
"api": {
|
79
|
+
"version": "1.0.1",
|
80
|
+
"when": "Tue Nov 01 05:34:41 UTC 2011",
|
81
|
+
"what": "clips",
|
82
|
+
"message": "Unauthorized",
|
83
|
+
"status": 401
|
84
|
+
},
|
85
|
+
"clip": {
|
86
|
+
}
|
87
|
+
}
|
88
|
+
```
|
89
|
+
|
90
|
+
#### Not Found
|
91
|
+
|
92
|
+
HTTP Status 404. The resource requested was not found.
|
93
|
+
|
94
|
+
```json
|
95
|
+
{
|
96
|
+
"api": {
|
97
|
+
"version": "1.0.1",
|
98
|
+
"when": "Tue Nov 01 05:48:05 UTC 2011",
|
99
|
+
"what": "clip",
|
100
|
+
"message": "Not Found",
|
101
|
+
"status": 404
|
102
|
+
},
|
103
|
+
"clip": {
|
104
|
+
}
|
105
|
+
}
|
106
|
+
```
|
107
|
+
|
108
|
+
#### Unprocessable Entity
|
109
|
+
|
110
|
+
HTTP Status 422. The URI of the query did not map to any resources currently
|
111
|
+
presented by the API.
|
112
|
+
|
113
|
+
```json
|
114
|
+
{
|
115
|
+
"api": {
|
116
|
+
"version": "1.0.1",
|
117
|
+
"when": "Tue Nov 01 05:48:54 UTC 2011",
|
118
|
+
"what": "noob",
|
119
|
+
"message": "Unprocessable Entity",
|
120
|
+
"status": 422
|
121
|
+
}
|
122
|
+
}
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
### Clip JSON
|
127
|
+
|
128
|
+
#### Request
|
129
|
+
|
130
|
+
```shell
|
131
|
+
curl -H "X-HarkToken: a-token" "https://api.hark.com/1.0/clips/jxxcfhxywx.json"
|
132
|
+
```
|
133
|
+
|
134
|
+
#### Attributes
|
135
|
+
|
136
|
+
* audio_url - A CDN URL to the audio portion of the clip. URL will have expiry information attached to it, and will expire in 60 minutes from the time of the request.
|
137
|
+
* canonical_url - Unique URL of the clip.
|
138
|
+
* description - A description of the clip.
|
139
|
+
* duration - The clip's duration in seconds.
|
140
|
+
* image_urls - An array of images associated with the clip.
|
141
|
+
* name - The name of the clip.
|
142
|
+
* pid - Unique identifier of the clip.
|
143
|
+
* quote - A distinctive quote from the clip.
|
144
|
+
* short_url - A bit.ly shortened URL to the clip.
|
145
|
+
|
146
|
+
#### Example
|
147
|
+
|
148
|
+
```json
|
149
|
+
{
|
150
|
+
"api": {
|
151
|
+
"version": "1.0.1",
|
152
|
+
"when": "Tue Nov 01 05:58:46 UTC 2011",
|
153
|
+
"what": "clip",
|
154
|
+
"message": "OK",
|
155
|
+
"status": 200
|
156
|
+
},
|
157
|
+
"clip": {
|
158
|
+
"audio_url": "*** A VALID EXPIRING CDN AUDIO URL ***",
|
159
|
+
"canonical_url": "http://hark.com/clips/jxxcfhxywx-i-have-a-dream-today",
|
160
|
+
"description": "Martin Luther King Jr. gives his I Have a Dream Speech.",
|
161
|
+
"duration": 2,
|
162
|
+
"image_urls": [
|
163
|
+
"http://cdn2.hark.com/images/000/000/224/224/martin-luther-king-jr_large.jpg"
|
164
|
+
],
|
165
|
+
"name": "I have a dream today",
|
166
|
+
"pid": "jxxcfhxywx",
|
167
|
+
"quote": "\"I have a dream today!\"",
|
168
|
+
"short_url": "http://bit.ly/fPKQmO"
|
169
|
+
}
|
170
|
+
}
|
171
|
+
```
|
172
|
+
|
173
|
+
### Clips Search JSON
|
174
|
+
|
175
|
+
#### Request
|
176
|
+
|
177
|
+
```shell
|
178
|
+
curl -H "X-HarkToken: a-token" "https://api.hark.com/1.0/clips/search?keywords=a+search+phrase"
|
179
|
+
```
|
180
|
+
|
181
|
+
#### Attributes
|
182
|
+
|
183
|
+
* clips - An array of clips specified above.
|
184
|
+
|
185
|
+
#### Example
|
186
|
+
|
187
|
+
```json
|
188
|
+
{
|
189
|
+
"clips": [
|
190
|
+
{ SEE CLIP DESCRIPTION ABOVE },
|
191
|
+
{ SEE CLIP DESCRIPTION ABOVE },
|
192
|
+
{ SEE CLIP DESCRIPTION ABOVE }
|
193
|
+
],
|
194
|
+
"api": {
|
195
|
+
"version": "1.0.1",
|
196
|
+
"when": "Tue Nov 01 06:10:11 UTC 2011",
|
197
|
+
"what": "clips",
|
198
|
+
"message": "OK",
|
199
|
+
"status": 200
|
200
|
+
}
|
201
|
+
}
|
202
|
+
```
|
203
|
+
|
204
|
+
### Collection JSON
|
205
|
+
|
206
|
+
#### Request
|
207
|
+
|
208
|
+
```shell
|
209
|
+
curl -H "X-HarkToken: a-token" "https://api.hark.com/1.0/collections/nfngpynlrd.json"
|
210
|
+
```
|
211
|
+
|
212
|
+
#### Attributes
|
213
|
+
|
214
|
+
* canonical_url - Unique URL of the collection.
|
215
|
+
* clip_pids - Array of clip pids belonging to the collection.
|
216
|
+
* description - A description of the collection.
|
217
|
+
* image_urls - Array of images belonging to the collection.
|
218
|
+
* name - The name of the collection.
|
219
|
+
* pid - Unique identifier of the collection.
|
220
|
+
* short_url - A bit.ly shortened URL to the collection.
|
221
|
+
|
222
|
+
#### Example
|
223
|
+
|
224
|
+
```json
|
225
|
+
{
|
226
|
+
"api": {
|
227
|
+
"version": "1.0.1",
|
228
|
+
"when": "Tue Nov 01 06:21:28 UTC 2011",
|
229
|
+
"what": "collection",
|
230
|
+
"message": "OK",
|
231
|
+
"status": 200
|
232
|
+
},
|
233
|
+
"collection": {
|
234
|
+
"canonical_url": "http://hark.com/collections/nfngpynlrd-the-godfather",
|
235
|
+
"clip_pids": [
|
236
|
+
"jtpmzgfktg",
|
237
|
+
"mdgnglbypn",
|
238
|
+
"vlbldnhdlc",
|
239
|
+
"kmbksnnsry"
|
240
|
+
],
|
241
|
+
"description": "The Godfather is a 1972 American crime drama film based on the 1969 novel ...",
|
242
|
+
"image_urls": [
|
243
|
+
"http://cdn0.hark.com/images/000/001/572/1572/the-godfather_large.jpg",
|
244
|
+
"http://cdn2.hark.com/images/000/046/310/46310/the-godfather_large.jpg",
|
245
|
+
"http://cdn2.hark.com/images/000/425/462/425462/the-godfather_large.jpg"
|
246
|
+
],
|
247
|
+
"name": "The Godfather",
|
248
|
+
"pid": "nfngpynlrd",
|
249
|
+
"short_url": "http://hark.com/collections/nfngpynlrd-the-godfather"
|
250
|
+
}
|
251
|
+
}
|
252
|
+
```
|
253
|
+
|
254
|
+
### Collections Search JSON
|
255
|
+
|
256
|
+
#### Request
|
257
|
+
|
258
|
+
```shell
|
259
|
+
curl -H "X-HarkToken: a-token" "https://api.hark.com/1.0/collections/search?keywords=a+search+phrase"
|
260
|
+
```
|
261
|
+
|
262
|
+
#### Attributes
|
263
|
+
|
264
|
+
* collections - An array of collections specified above.
|
265
|
+
|
266
|
+
#### Example
|
267
|
+
|
268
|
+
```json
|
269
|
+
{
|
270
|
+
"collections": [
|
271
|
+
{ SEE COLLECTION DESCRIPTION ABOVE },
|
272
|
+
{ SEE COLLECTION DESCRIPTION ABOVE },
|
273
|
+
{ SEE COLLECTION DESCRIPTION ABOVE }
|
274
|
+
],
|
275
|
+
"api": {
|
276
|
+
"version": "1.0.1",
|
277
|
+
"when": "Tue Nov 01 06:10:11 UTC 2011",
|
278
|
+
"what": "collections",
|
279
|
+
"message": "OK",
|
280
|
+
"status": 200
|
281
|
+
}
|
282
|
+
}
|
283
|
+
```
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
288
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
289
|
+
!! The Ruby implementation is a work in progress. The interface will likely !!
|
290
|
+
!! change as well as be expanded upon. !!
|
291
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
292
|
+
|
293
|
+
|
294
|
+
Ruby Examples
|
295
|
+
-------------
|
296
|
+
|
297
|
+
Configure the API and fetch a clip.
|
298
|
+
|
299
|
+
```ruby
|
300
|
+
require 'hark'
|
301
|
+
|
302
|
+
Hark::API.configure do |config|
|
303
|
+
config.api_key = 'the-key'
|
304
|
+
end
|
305
|
+
|
306
|
+
Hark::API.clip('jxxcfhxywx') # returns JSON
|
307
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the hark gem'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << ['lib', 'test']
|
11
|
+
t.pattern = 'test/**/test_*.rb'
|
12
|
+
t.options = ["--verbose=verbose"] # (s[ilent], p[rogress], n[ormal], v[erbose])
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Generate documentation for the hark gem"
|
16
|
+
task :doc => ['doc:generate']
|
17
|
+
|
18
|
+
namespace :doc do
|
19
|
+
|
20
|
+
project_root = File.expand_path(File.dirname(__FILE__))
|
21
|
+
doc_destination = File.join(project_root, 'doc')
|
22
|
+
|
23
|
+
begin
|
24
|
+
require 'rdoc'
|
25
|
+
require 'yard'
|
26
|
+
require 'rdiscount'
|
27
|
+
YARD::Rake::YardocTask.new(:generate) do |t|
|
28
|
+
t.files = ['lib/**/*.rb']
|
29
|
+
t.options = ['--output-dir', doc_destination, '--readme', 'README.md']
|
30
|
+
end
|
31
|
+
rescue LoadError
|
32
|
+
desc "Generate YARD Documentation"
|
33
|
+
task :generate do
|
34
|
+
abort "Please install the yard and rdiscount gems to generate rdoc."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Remove generated documentation"
|
39
|
+
task :clean do
|
40
|
+
rm_r doc_destination if File.exists?(doc_destination)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/hark.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "hark/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hark"
|
7
|
+
s.version = Hark::VERSION
|
8
|
+
s.authors = ["Mike Mondragon", "Wes Maldonado"]
|
9
|
+
s.email = ["mikemondragon@gmail.com", "wes@brokenbuild.com"]
|
10
|
+
s.homepage = "http://www.hark.com/"
|
11
|
+
s.summary = %q{A Ruby Gem to access the hark.com API}
|
12
|
+
s.description = %q{hark.com is a site that publishes movie quote sound bites
|
13
|
+
and still images. This gem is used to access this
|
14
|
+
information in a programatic fashion.}
|
15
|
+
|
16
|
+
s.rubyforge_project = "hark"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency "httparty"
|
24
|
+
s.add_runtime_dependency "activesupport"
|
25
|
+
s.add_development_dependency "mocha"
|
26
|
+
s.add_development_dependency "rdoc"
|
27
|
+
s.add_development_dependency "yard"
|
28
|
+
s.add_development_dependency "rdiscount"
|
29
|
+
end
|
data/lib/hark.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "httparty"
|
4
|
+
require "active_support"
|
5
|
+
require "active_support/core_ext/object/blank"
|
6
|
+
|
7
|
+
module Hark
|
8
|
+
|
9
|
+
autoload :VERSION, 'hark/version'
|
10
|
+
autoload :API, 'hark/api'
|
11
|
+
autoload :Configuration, 'hark/configuration'
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
# An environment object used for configuration.
|
16
|
+
def env
|
17
|
+
@_env ||= ActiveSupport::StringInquirer.new(ENV["HARK_ENV"] || "production")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/hark/api.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Hark
|
2
|
+
class API
|
3
|
+
|
4
|
+
include ::HTTParty
|
5
|
+
|
6
|
+
if Hark.env.production?
|
7
|
+
base_uri 'https://api.hark.com/1.0'
|
8
|
+
else
|
9
|
+
base_uri 'http://api.hark.dev/1.0'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Queries the API for the clip JSON
|
13
|
+
# @param [String] clip_id The clip identifier
|
14
|
+
# @return [String] Returns a JSON representation of the clip.
|
15
|
+
def clip( clip_id )
|
16
|
+
self.class.get("/clips/#{clip_id}.json", options)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Queries the API for the search term
|
20
|
+
# @param [String] search_term The clip identifier
|
21
|
+
# @return [String] Returns a JSON array of clips
|
22
|
+
def search(search_term)
|
23
|
+
search_options = options
|
24
|
+
search_options[:query] = { 'keywords' => search_term }
|
25
|
+
puts search_options
|
26
|
+
self.class.get("/clips/search.json", search_options)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Default options passed back to in a HTTParty call.
|
30
|
+
# @return [Hash] Returns hash of options for a HTTParty call.
|
31
|
+
def options
|
32
|
+
{ :headers => { 'X-HarkToken' => self.class.configuration.api_key } }
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
|
37
|
+
# Configuration object. Acts like a hash and return sensible values for
|
38
|
+
# all configuration options. See Hark::Configuration.
|
39
|
+
attr_writer :configuration
|
40
|
+
|
41
|
+
# Call this method to configure the library at runtime.
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# Hark::API.configure do |config|
|
45
|
+
# config.api_key = '1234567890abcdef'
|
46
|
+
# end
|
47
|
+
def configure
|
48
|
+
yield(configuration)
|
49
|
+
@api ||= API.new
|
50
|
+
end
|
51
|
+
|
52
|
+
# The configuration object.
|
53
|
+
# @see Hark::API.configure
|
54
|
+
def configuration
|
55
|
+
@configuration ||= Configuration.new
|
56
|
+
end
|
57
|
+
|
58
|
+
# The api object.
|
59
|
+
# @see Hark::API
|
60
|
+
def api
|
61
|
+
raise ArgumentError if configuration.api_key.blank?
|
62
|
+
@api
|
63
|
+
end
|
64
|
+
|
65
|
+
# Queries the API for the clip JSON.
|
66
|
+
# @see Hark::API#clip
|
67
|
+
def clip(clip_id)
|
68
|
+
api.clip(clip_id)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Queries the API for the search term
|
72
|
+
# @see Hark::API#search
|
73
|
+
def search(search_term)
|
74
|
+
api.search(search_term)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/hark/version.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://api.hark.com:443/1.0/clips/jxxcfhxywx.json
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
x-harktoken:
|
9
|
+
- an-api-key
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
x-ua-compatible:
|
16
|
+
- IE=Edge,chrome=1
|
17
|
+
etag:
|
18
|
+
- "\"e699d0aaa3334eedecb6a2732239280f\""
|
19
|
+
x-powered-by:
|
20
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.2
|
21
|
+
content-type:
|
22
|
+
- application/json; charset=utf-8
|
23
|
+
x-rack-cache:
|
24
|
+
- miss
|
25
|
+
server:
|
26
|
+
- Apache/2.2.3 (CentOS)
|
27
|
+
date:
|
28
|
+
- Fri, 28 Oct 2011 05:46:00 GMT
|
29
|
+
x-runtime:
|
30
|
+
- "0.072499"
|
31
|
+
cache-control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
vary:
|
34
|
+
- Host,X-Forwarded-Proto
|
35
|
+
status:
|
36
|
+
- "200"
|
37
|
+
transfer-encoding:
|
38
|
+
- chunked
|
39
|
+
body: |-
|
40
|
+
{
|
41
|
+
"pid": "jxxcfhxywx",
|
42
|
+
"name": "I have a dream today",
|
43
|
+
"duration": 2,
|
44
|
+
"short_url": "http://bit.ly/fPKQmO",
|
45
|
+
"canonical_url": "http://hark.com/clips/jxxcfhxywx-i-have-a-dream-today",
|
46
|
+
"version": "1.0.1",
|
47
|
+
"audio_url": "http://audio1.hark.com/002BB7/production/audio/000/000/001/1.mp3?Expires=1319784360&Signature=ecFLDwVqaWqTD~KFpbCtjSgof1icL5IklpN1lt~DjUOZO0thGGUmTdUS4UcLwxcdYGIi0bBZDpVh7kM6CFhbWFKm5m~X4i5Y-ffPu9Mhc~ENa-O6-zQbVy5bSc2H4-L8XMn8uElUPKkxXHsN2Th9Up4dP~H5Lb4GKMrqQaAg~UA_&Key-Pair-Id=APKAJQKB5APWST65Q4AQ",
|
48
|
+
"what": "clip",
|
49
|
+
"quote": "\"I have a dream today!\"",
|
50
|
+
"description": "Martin Luther King Jr. gives his I Have a Dream Speech.",
|
51
|
+
"image_urls": [
|
52
|
+
"http://cdn2.hark.com/images/000/000/224/224/martin-luther-king-jr_large.jpg"
|
53
|
+
]
|
54
|
+
}
|
55
|
+
http_version: "1.1"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://api.hark.com:443/1.0/clips/foo.json
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
x-harktoken:
|
9
|
+
- an-api-key
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 404
|
13
|
+
message: Not Found
|
14
|
+
headers:
|
15
|
+
x-ua-compatible:
|
16
|
+
- IE=Edge,chrome=1
|
17
|
+
x-powered-by:
|
18
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.2
|
19
|
+
content-type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
x-rack-cache:
|
22
|
+
- miss
|
23
|
+
server:
|
24
|
+
- Apache/2.2.3 (CentOS)
|
25
|
+
date:
|
26
|
+
- Fri, 28 Oct 2011 05:33:00 GMT
|
27
|
+
x-runtime:
|
28
|
+
- "1.052981"
|
29
|
+
cache-control:
|
30
|
+
- no-cache
|
31
|
+
vary:
|
32
|
+
- Host,X-Forwarded-Proto
|
33
|
+
status:
|
34
|
+
- "404"
|
35
|
+
transfer-encoding:
|
36
|
+
- chunked
|
37
|
+
body: |-
|
38
|
+
{
|
39
|
+
"pid": "foo",
|
40
|
+
"what": "clip",
|
41
|
+
"message": "Not Found",
|
42
|
+
"status": 404
|
43
|
+
}
|
44
|
+
http_version: "1.1"
|
data/test/test_hark.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestHarkAPI < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "getting clips" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
Hark::API.configuration.api_key = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
should "raise error when api key not set" do
|
12
|
+
assert_raise(ArgumentError) { Hark::API.clip('jxxcfhxywx') }
|
13
|
+
end
|
14
|
+
|
15
|
+
should "fail getting a clip for a non-existent clip id" do
|
16
|
+
Hark::API.configure do |config|
|
17
|
+
config.api_key = 'an-api-key'
|
18
|
+
end
|
19
|
+
|
20
|
+
VCR.use_cassette('non-existent-clip') do
|
21
|
+
json = Hark::API.clip('foo').body
|
22
|
+
result = JSON.parse(json).symbolize_keys
|
23
|
+
|
24
|
+
expected = { :status => 404, :message => 'Not Found', :pid => 'foo', :what => 'clip' }
|
25
|
+
assert_equal expected, result
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
should "get a clip" do
|
30
|
+
|
31
|
+
Hark::API.configure do |config|
|
32
|
+
config.api_key = 'an-api-key'
|
33
|
+
end
|
34
|
+
|
35
|
+
VCR.use_cassette('existing-clip') do
|
36
|
+
json = Hark::API.clip('jxxcfhxywx').body
|
37
|
+
result = JSON.parse(json).symbolize_keys
|
38
|
+
# TODO implement when updates for API are deployed
|
39
|
+
# assert_equal 200, result[:status]
|
40
|
+
# assert_equal 'Success', result[:message]
|
41
|
+
assert_equal 'jxxcfhxywx', result[:pid]
|
42
|
+
assert_equal 'clip', result[:what]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context "searching for clips" do
|
49
|
+
|
50
|
+
should "should raise error when api key not set"
|
51
|
+
|
52
|
+
should "get a result with zero clips"
|
53
|
+
|
54
|
+
should "get a result with many clips"
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
context "getting collections" do
|
59
|
+
|
60
|
+
should "fail getting a collection and having a bad api key"
|
61
|
+
|
62
|
+
should "fail getting a collection for a non-existent collection id"
|
63
|
+
|
64
|
+
should "get a collection"
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
context "searching for collections" do
|
69
|
+
|
70
|
+
should "should raise error when api key not set"
|
71
|
+
|
72
|
+
should "get a result with zero collections"
|
73
|
+
|
74
|
+
should "get a result with many collections"
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestHarkConfiguration < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "the instance" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@configuration = Hark::Configuration.new
|
9
|
+
@configuration.api_key = "abc123"
|
10
|
+
end
|
11
|
+
|
12
|
+
should "have api key set" do
|
13
|
+
assert_equal "abc123", @configuration.api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
context "the configuration" do
|
19
|
+
|
20
|
+
|
21
|
+
should "configure the api key in the configure block" do
|
22
|
+
|
23
|
+
Hark::API.configure do |config|
|
24
|
+
config.api_key = '1234567890abcdef'
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal '1234567890abcdef', Hark::API.configuration.api_key
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
%W{
|
2
|
+
pp
|
3
|
+
test/unit
|
4
|
+
mocha
|
5
|
+
shoulda
|
6
|
+
vcr
|
7
|
+
json/pure
|
8
|
+
active_support/hash_with_indifferent_access
|
9
|
+
}.each do |g|
|
10
|
+
begin
|
11
|
+
require g
|
12
|
+
rescue LoadError
|
13
|
+
require 'rubygems'
|
14
|
+
require g
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'json/pure'
|
19
|
+
|
20
|
+
VCR.config do |c|
|
21
|
+
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
22
|
+
c.stub_with :webmock
|
23
|
+
end
|
24
|
+
|
25
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'hark'))
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
|
29
|
+
def assert_true(what)
|
30
|
+
assert_equal true, what
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_false(what)
|
34
|
+
assert_equal false, what
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hark
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mike Mondragon
|
14
|
+
- Wes Maldonado
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-11-14 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: mocha
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rdoc
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: yard
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rdiscount
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :development
|
104
|
+
version_requirements: *id006
|
105
|
+
description: |-
|
106
|
+
hark.com is a site that publishes movie quote sound bites
|
107
|
+
and still images. This gem is used to access this
|
108
|
+
information in a programatic fashion.
|
109
|
+
email:
|
110
|
+
- mikemondragon@gmail.com
|
111
|
+
- wes@brokenbuild.com
|
112
|
+
executables: []
|
113
|
+
|
114
|
+
extensions: []
|
115
|
+
|
116
|
+
extra_rdoc_files: []
|
117
|
+
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- hark.gemspec
|
125
|
+
- lib/hark.rb
|
126
|
+
- lib/hark/api.rb
|
127
|
+
- lib/hark/configuration.rb
|
128
|
+
- lib/hark/version.rb
|
129
|
+
- test/fixtures/vcr_cassettes/existing-clip.yml
|
130
|
+
- test/fixtures/vcr_cassettes/non-existent-clip.yml
|
131
|
+
- test/test_hark.rb
|
132
|
+
- test/test_hark_api.rb
|
133
|
+
- test/test_hark_configuration.rb
|
134
|
+
- test/test_hark_version.rb
|
135
|
+
- test/test_helper.rb
|
136
|
+
homepage: http://www.hark.com/
|
137
|
+
licenses: []
|
138
|
+
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
version: "0"
|
162
|
+
requirements: []
|
163
|
+
|
164
|
+
rubyforge_project: hark
|
165
|
+
rubygems_version: 1.8.6
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: A Ruby Gem to access the hark.com API
|
169
|
+
test_files:
|
170
|
+
- test/fixtures/vcr_cassettes/existing-clip.yml
|
171
|
+
- test/fixtures/vcr_cassettes/non-existent-clip.yml
|
172
|
+
- test/test_hark.rb
|
173
|
+
- test/test_hark_api.rb
|
174
|
+
- test/test_hark_configuration.rb
|
175
|
+
- test/test_hark_version.rb
|
176
|
+
- test/test_helper.rb
|
177
|
+
has_rdoc:
|