clarify 1.1.1 → 2.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -16
  3. data/.rspec +2 -0
  4. data/.simplecov +3 -0
  5. data/.travis.yml +7 -0
  6. data/CHANGELOG.md +4 -0
  7. data/Dockerfile +11 -0
  8. data/Gemfile +2 -2
  9. data/LICENSE +1 -1
  10. data/README.md +202 -47
  11. data/Rakefile +62 -4
  12. data/clarify.gemspec +10 -7
  13. data/cucumber.yml +1 -0
  14. data/features/create-bundles.feature +10 -0
  15. data/features/delete-bundle.feature +7 -0
  16. data/features/identity-steps.feature +6 -0
  17. data/features/list-bundles.feature +13 -0
  18. data/features/search-bundles.feature +10 -0
  19. data/features/step_definitions/curied_url_steps.rb +6 -0
  20. data/features/step_definitions/error_steps.rb +4 -0
  21. data/features/step_definitions/http_verification_step.rb +4 -0
  22. data/features/step_definitions/identity_steps.rb +12 -0
  23. data/features/step_definitions/list_steps.rb +76 -0
  24. data/features/support/env.rb +36 -0
  25. data/features/support/lib/curies.rb +19 -0
  26. data/features/support/lib/customer.rb +41 -0
  27. data/features/support/lib/exceptions.rb +27 -0
  28. data/features/support/lib/names.rb +16 -0
  29. data/lib/clarify.rb +16 -14
  30. data/lib/clarify/bundle_repository.rb +26 -0
  31. data/lib/clarify/client.rb +51 -0
  32. data/lib/clarify/collection_iterator.rb +27 -0
  33. data/lib/clarify/configuration.rb +29 -7
  34. data/lib/clarify/errors.rb +22 -0
  35. data/lib/clarify/response.rb +29 -0
  36. data/lib/clarify/response_factory.rb +34 -0
  37. data/lib/clarify/responses/bundle.rb +11 -0
  38. data/lib/clarify/responses/collection.rb +31 -0
  39. data/lib/clarify/responses/no_body.rb +13 -0
  40. data/lib/clarify/responses/search_collection.rb +18 -0
  41. data/lib/clarify/responses/tracks.rb +15 -0
  42. data/lib/clarify/rest_client.rb +129 -0
  43. data/lib/clarify/version.rb +3 -1
  44. data/spec/clarify/bundle_repository_spec.rb +37 -0
  45. data/spec/clarify/client_spec.rb +93 -0
  46. data/spec/clarify/collection_iterator_spec.rb +86 -0
  47. data/spec/clarify/configuration_spec.rb +77 -0
  48. data/spec/clarify/errors_spec.rb +15 -0
  49. data/spec/clarify/response_factory_spec.rb +51 -0
  50. data/spec/clarify/response_spec.rb +69 -0
  51. data/spec/clarify/responses/bundle_spec.rb +8 -0
  52. data/spec/clarify/responses/collection_spec.rb +58 -0
  53. data/spec/clarify/responses/search_collection_spec.rb +40 -0
  54. data/spec/clarify/responses/tracks_spec.rb +18 -0
  55. data/spec/clarify/rest_client_spec.rb +222 -0
  56. data/spec/spec_helper.rb +4 -9
  57. data/src_readme/README_no_output.md +186 -0
  58. data/src_readme/examples/bundle_create.rb +11 -0
  59. data/src_readme/examples/bundle_fetch.rb +9 -0
  60. data/src_readme/examples/bundles_list_fetch.rb +11 -0
  61. data/src_readme/examples/bundles_paged_over.rb +8 -0
  62. data/src_readme/examples/bundles_search.rb +20 -0
  63. data/src_readme/examples/list_bundles.rb +6 -0
  64. data/src_readme/examples/searches_paged_over.rb +10 -0
  65. data/src_readme/examples/setup.rb +5 -0
  66. data/src_readme/make.rb +56 -0
  67. data/src_readme/readme.md.erb +55 -0
  68. metadata +127 -62
  69. data/LICENSE.txt +0 -24
  70. data/examples/create.rb +0 -14
  71. data/examples/delete.rb +0 -12
  72. data/examples/list.rb +0 -14
  73. data/examples/search.rb +0 -26
  74. data/examples/test.rb +0 -15
  75. data/lib/clarify/bundle.rb +0 -40
  76. data/lib/clarify/metadata.rb +0 -26
  77. data/lib/clarify/request.rb +0 -37
  78. data/lib/clarify/search.rb +0 -10
  79. data/lib/clarify/track.rb +0 -40
  80. data/spec/lib/clarify/bundle_spec.rb +0 -43
  81. data/spec/lib/clarify/configuration_spec.rb +0 -19
  82. data/spec/lib/clarify/metadata_spec.rb +0 -36
  83. data/spec/lib/clarify/search_spec.rb +0 -22
  84. data/spec/lib/clarify/track_spec.rb +0 -81
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18179d891742e09939fedb3b2073db80bf3e87f9
4
- data.tar.gz: 70e075ae0bd8788d63663dd4f4fc3697f57cdd7c
3
+ metadata.gz: 27ee463c9c617e7b5fe25e15bcab7a015b2a773d
4
+ data.tar.gz: aa70eb477ccd681645764b8c60140acbb389cb2e
5
5
  SHA512:
6
- metadata.gz: 0489cdd40b5e83b8f46f5fa6a0ccecd3581ec13fbc3e1be6022d76041fcb68fcdcd101f5185627f9f411e5239aaa163d021532f9b8a303c45856fb829a6138cf
7
- data.tar.gz: 40a9112bf243b525e4c80f01b8a3371ca9c086077c2ec68c38597cdb11c02594d63ed960c91794b6809178a0591c0bdfe8d8314995487482f3232af22cdd38e2
6
+ metadata.gz: cfa320f5bf403e49fca2ff15569f4dfdbe8968cafc9e82c13c440b26bce52d9e9501037b4914ad97521e7bae6359d2298f6aa9ce8e1cc5b73383f0ee334ba770
7
+ data.tar.gz: 9bf3beeef829c852382395da189228cf0844320373d3992a2308fe8ac80ffb809b37508d035a7f56fdbf482d5dac2c7dfaa5df929cb543e8b21b2e80f3b08403
data/.gitignore CHANGED
@@ -1,18 +1,4 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
1
  Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
2
  coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .idea/*
3
+ *.sw*
4
+
data/.rspec CHANGED
@@ -1,3 +1,5 @@
1
1
  --color
2
+ --tty
2
3
  --require spec_helper
3
4
  --format=documentation
5
+ --order rand
@@ -0,0 +1,3 @@
1
+ SimpleCov.start do
2
+ SimpleCov.minimum_coverage 100
3
+ end
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby-head
4
+ - 2.2.1
5
+ env:
6
+ global:
7
+ secure: Lshn6Nxm71QuAJmo3AuF4N0UmsRzXwXY2WZhYXOQgfyIe3YibO/MyqQKWQx0CE3UcuR8gEQAA35potLZxXBk0OCbtrJ7UWdVVWp7NkAbWK05f5KAK2R7XT8/5IEPUlicmE/UnnPsJ08z2hG64ncGA0gmUaY/B+OAqeRfim3umh4=
@@ -0,0 +1,4 @@
1
+ # v2.0.0.alpha.1
2
+
3
+ Rebuilt the client to more closely match the intended usage of the API itself.
4
+
@@ -0,0 +1,11 @@
1
+ FROM ruby:latest
2
+
3
+ RUN mkdir -p /data/lib/clarify/
4
+ WORKDIR /data
5
+ ADD Gemfile clarify.gemspec /data/
6
+ ADD lib/clarify/version.rb /data/lib/clarify/version.rb
7
+ RUN bundle install
8
+
9
+ ADD features /data/features
10
+
11
+ ENTRYPOINT [ "rake" ]
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in clarify.gemspec
4
3
  gemspec
4
+
data/LICENSE CHANGED
@@ -2,7 +2,7 @@ The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2014 Clarify, Inc
4
4
 
5
- Written by Nola Stowe @rubygeek
5
+ Written by Clarify Inc. support@clarify.io
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,93 +1,248 @@
1
- [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Clarify/clarify-ruby/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Clarify/clarify-ruby/?branch=master) [![Code Climate](https://codeclimate.com/github/Clarify/clarify-ruby/badges/gpa.svg)](https://codeclimate.com/github/Clarify/clarify-ruby)
2
1
 
3
- # Clarify
2
+ [![Build Status][travis-image]][travis-url] [![Code Climate][cc-image]][cc-url]
4
3
 
5
- A gem to communicate with the ClarifyAPI.
4
+ # How To
6
5
 
7
- ### Installation
6
+ You can get started in minutes using our Quickstarts:
8
7
 
9
- Add this line to your application's Gemfile:
8
+ [http://clarify.io/docs/quickstarts/](http://clarify.io/docs/quickstarts/)
10
9
 
11
- gem 'clarify'
10
+ ## Basic Setup and Examples
12
11
 
13
- And then execute:
12
+ Require the library and initialize the Client, which takes care of
13
+ configuration and http client setup.
14
14
 
15
- $ bundle
15
+ ```ruby
16
+ # setup.rb
17
+ require 'clarify'
18
+ require 'pp'
19
+
20
+ clarify = Clarify::Client.new(api_key: 'docs-api-key')
21
+ pp clarify
22
+ ```
23
+
24
+ ### Search for bundles
25
+
26
+ ```ruby
27
+ # bundles_search.rb
28
+ require 'clarify'
29
+
30
+ clarify = Clarify::Client.new(api_key: 'docs-api-key')
16
31
 
17
- Or install it yourself as:
32
+ results = clarify.bundles.search('plane')
18
33
 
19
- $ gem install clarify
34
+ results.each do |bundle_results, bundle_url|
35
+ # Fetch the bundle:
36
+ bundle = clarify.get(bundle_url)
20
37
 
21
- add a configuration block to an initializer if you are using rails or in an include file:
38
+ puts "#{bundle.name} - #{bundle_url}"
39
+ bundle_results['term_results'].each do |term_result|
40
+ term_result['matches'].each do |match|
41
+ type = match['type']
42
+ match['hits'].each do |hit|
43
+ puts "\tmatched #{type} content at #{hit['start']} to #{hit['end']}"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ ```
22
49
 
50
+ Example output of bundles_search.rb:
51
+ ```
52
+ The Future of Women in Flying - /v1/bundles/3fbca3fe3678495fb08fe939dbe4f1cd
53
+ matched audio content at 68.92 to 69.31
54
+ First American in Earth Orbit - /v1/bundles/72aaa17a9da745c9be41ab64b60319cb
55
+ matched audio content at 99.25 to 99.43
23
56
  ```
57
+
58
+ ### Get a list of bundles
59
+
60
+ ```ruby
61
+ # list_bundles.rb
24
62
  require 'clarify'
63
+ clarify = Clarify::Client.new(api_key: 'docs-api-key')
25
64
 
26
- Clarify.configure do |config|
27
- config.api_key = 'CLARIFY_API_KEY'
28
- # if key in ENV
29
- # config.api_key = ENV['CLARIFY_API_KEY']
30
- config.version = 1 #default is latest api version
65
+ clarify.bundles.fetch.each do |bundle_url|
66
+ puts " - #{bundle_url}"
31
67
  end
32
68
  ```
33
69
 
34
- It doesn't have to be in ENV variable but that is an option.
70
+ Example output of list_bundles.rb:
71
+ ```
72
+ - /v1/bundles/3fbca3fe3678495fb08fe939dbe4f1cd
73
+ - /v1/bundles/2a112c5b3e944802b932b0ddbf068c37
74
+ - /v1/bundles/ca4fbc504c6940cd96f270a0ca903917
75
+ - /v1/bundles/378efa8d163240478ae7d460c20fdb41
76
+ - /v1/bundles/4577432c51ab4fcdbed34be16ba363a2
77
+ - /v1/bundles/72aaa17a9da745c9be41ab64b60319cb
78
+ - /v1/bundles/2a0a63d07c6b46f99638edb961bc08f6
79
+ - /v1/bundles/45a8a6849e1948cea8bbb8dcb3440b68
80
+ ```
35
81
 
36
- **Remember never to check in your API key to a public repository!**
82
+ ### Fetch a particular bundle
37
83
 
38
- Your API key is found on your [application page](https://developer.clarify.io/apps/list/).
84
+ ```ruby
85
+ # bundle_fetch.rb
86
+ require 'clarify'
87
+ require 'pp'
39
88
 
40
- If you wish to store your API key in your environment:
89
+ clarify = Clarify::Client.new(api_key: 'docs-api-key')
41
90
 
42
- In bash:
91
+ bundle_url = '/v1/bundles/3fbca3fe3678495fb08fe939dbe4f1cd'
92
+ bundle = clarify.get(bundle_url)
93
+ puts "Bundle Name: #{bundle.name}"
94
+ pp bundle
95
+ ```
43
96
 
44
- export CLARIFY_API_KEY=atYIFLDSDFsdfssSsd+fsfsdfsd+p+PCwA
97
+ Example output of bundle_fetch.rb:
98
+ ```
99
+ Bundle Name: The Future of Women in Flying
100
+ #<Clarify::Responses::Bundle:0x007fc9c3171918
101
+ @body=
102
+ {"id"=>"3fbca3fe3678495fb08fe939dbe4f1cd",
103
+ "version"=>1,
104
+ "type"=>"audio",
105
+ "name"=>"The Future of Women in Flying",
106
+ "created"=>"2014-04-08T18:37:35.420Z",
107
+ "updated"=>"2014-04-08T18:37:35.420Z",
108
+ "_class"=>"Bundle",
109
+ "_links"=>
110
+ {"self"=>{"href"=>"/v1/bundles/3fbca3fe3678495fb08fe939dbe4f1cd"},
111
+ "curies"=>
112
+ [{"href"=>"/docs/rels/{rel}", "name"=>"clarify", "templated"=>true}],
113
+ "clarify:metadata"=>
114
+ {"href"=>"/v1/bundles/3fbca3fe3678495fb08fe939dbe4f1cd/metadata"},
115
+ "clarify:tracks"=>
116
+ {"href"=>"/v1/bundles/3fbca3fe3678495fb08fe939dbe4f1cd/tracks"}}},
117
+ @response=#<Net::HTTPOK 200 OK readbody=true>>
118
+ ```
45
119
 
46
- If you don't want to load it in your bash file, you can add it on the command line:
120
+ ### Get a list of bundles and their names
47
121
 
48
- CLARIFY_API_KEY=atYIFLDSDFsdfssSsd+fsfsdfsd+p+PCwA rails s
122
+ ```ruby
123
+ # bundles_list_fetch.rb
124
+ require 'clarify'
125
+ require 'pp'
49
126
 
50
- Or on [Heroku](http://www.heroku)
127
+ clarify = Clarify::Client.new(api_key: 'docs-api-key')
51
128
 
52
- heroku config:set CLARIFY_API_KEY=atYIFLDSDFsdfssSsd+fsfsdfsd+p+PCwA
129
+ bundles = clarify.bundles.fetch
53
130
 
54
- [Read more on heroku environment variables](https://devcenter.heroku.com/articles/config-vars)
131
+ bundles.each do |url|
132
+ bundle = clarify.get(url)
133
+ puts " - Bundle Name: #{bundle.name}"
134
+ end
135
+ ```
55
136
 
56
- By default, it uses the newest version of the API.
137
+ Example output of bundles_list_fetch.rb:
138
+ ```
139
+ - Bundle Name: The Future of Women in Flying
140
+ - Bundle Name: Election Eve Campaign Speech
141
+ - Bundle Name: Address to the Women of America
142
+ - Bundle Name: Address to Congress - Baseball
143
+ - Bundle Name: On Black Power
144
+ - Bundle Name: First American in Earth Orbit
145
+ - Bundle Name: On Releasing the Watergate Tapes
146
+ - Bundle Name: Resignation Address
147
+ ```
57
148
 
58
- ## Usage
149
+ ### Create a bundle
59
150
 
60
- To begin using this library, initialize the Clarify object with your API key:
151
+ Here you will need your own API key. Creating the bundle will return a 204,
152
+ which means it has been Created, but is not done processing.
61
153
 
62
154
  ```ruby
155
+ # bundle_create.rb
63
156
  require 'clarify'
64
- @client = Clarify::Bundle.new
157
+ require 'pp'
158
+
159
+ clarify = Clarify::Client.new(api_key: ENV['CLARIFY_API_KEY'])
160
+
161
+ created_bundle = clarify.bundles.create!(
162
+ name: 'Harvard Sentences #1',
163
+ media_url: 'http://media.clarify.io/audio/samples/harvard-sentences-1.wav'
164
+ )
165
+
166
+ pp created_bundle
167
+ ```
168
+
169
+ Example output of bundle_create.rb:
170
+ ```
171
+ #<Clarify::Response:0x007ffb5428fc38
172
+ @body=
173
+ {"id"=>"415bd191442846a6839c88ae3956eb64",
174
+ "_class"=>"Ref",
175
+ "_links"=>
176
+ {"self"=>{"href"=>"/v1/bundles/415bd191442846a6839c88ae3956eb64"},
177
+ "curies"=>
178
+ [{"href"=>"/docs/rels/{rel}", "name"=>"clarify", "templated"=>true}],
179
+ "clarify:metadata"=>
180
+ {"href"=>"/v1/bundles/415bd191442846a6839c88ae3956eb64/metadata"},
181
+ "clarify:tracks"=>
182
+ {"href"=>"/v1/bundles/415bd191442846a6839c88ae3956eb64/tracks"}}},
183
+ @response=#<Net::HTTPCreated 201 Created readbody=true>>
65
184
  ```
66
185
 
67
- Then add an audio or video file to your search index:
186
+ ## More Advanced Usage
187
+ #
188
+ ### Get all of your searches over many pages
68
189
 
69
190
  ```ruby
70
- bundle = @client.create(:name => "Harvard Sentences",
71
- :media_url => "http://media.clarify.io/audio/samples/harvard-sentences-1.wav")
72
- bundle.data[:id]
191
+ # searches_paged_over.rb
192
+ require 'clarify'
193
+ require 'pp'
194
+
195
+ clarify = Clarify::Client.new(api_key: 'docs-api-key')
196
+
197
+ first_page = clarify.bundles.search('flight')
198
+ clarify.pager(first_page).each do |result, bundle_url|
199
+ puts " - #{clarify.get(bundle_url).name}"
200
+ pp result
201
+ end
202
+ ```
203
+
204
+ Example output of searches_paged_over.rb:
205
+ ```
206
+ - First American in Earth Orbit
207
+ {"score"=>1,
208
+ "term_results"=>
209
+ [{"score"=>0.379,
210
+ "matches"=>
211
+ [{"type"=>"audio",
212
+ "track"=>0,
213
+ "hits"=>
214
+ [{"start"=>67.41, "end"=>67.55}, {"start"=>92.76, "end"=>92.94}]}]}]}
73
215
  ```
74
216
 
75
- Within minutes your file will be added to your index and available via a simple search:
217
+ ### Get all of your bundles over many pages
76
218
 
77
219
  ```ruby
78
- @client = Clarify::Search.new
79
- results = @client.perform(:query => "dorothy").data
80
- bundles = results[:_links][:items]
220
+ # bundles_paged_over.rb
221
+ require 'clarify'
222
+
223
+ clarify = Clarify::Client.new(api_key: 'docs-api-key')
224
+
225
+ first_page = clarify.bundles.fetch
226
+ clarify.pager(first_page).each do |bundle_url|
227
+ puts " - #{clarify.get(bundle_url).name}"
228
+ end
81
229
  ```
82
230
 
83
- See more examples for listing, getting, and deleting bundles etc. in the /examples folder.
231
+ Example output of bundles_paged_over.rb:
232
+ ```
233
+ - The Future of Women in Flying
234
+ - Election Eve Campaign Speech
235
+ - Address to the Women of America
236
+ - Address to Congress - Baseball
237
+ - On Black Power
238
+ - First American in Earth Orbit
239
+ - On Releasing the Watergate Tapes
240
+ - Resignation Address
241
+ ```
84
242
 
85
- ## Contributing
86
243
 
87
- 1. Fork it to your github user ie: ( `http://github.com/my-github-username/clarify-ruby/` )
88
- 2. Create your feature branch and rspec tests (`git checkout -b my-new-feature`)
89
- 3. Run the rspec tests with `rake spec`
90
- 4. Commit your changes (`git commit -am 'Add some feature'`)
91
- 5. Push to the branch (`git push origin my-new-feature`)
92
- 6. Create new Pull Request
244
+ [travis-image]: https://travis-ci.org/Clarify/clarify-ruby.svg
245
+ [travis-url]: https://travis-ci.org/Clarify/clarify-ruby
93
246
 
247
+ [cc-image]: https://codeclimate.com/github/Clarify/clarify-ruby/badges/gpa.svg
248
+ [cc-url]: https://codeclimate.com/github/Clarify/clarify-ruby
data/Rakefile CHANGED
@@ -1,10 +1,68 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+ require 'cucumber/rake/task'
5
+ require 'rake/clean'
2
6
 
3
- require "rspec/core/rake_task"
7
+ CLEAN.include(FileList['coverage'])
8
+
9
+ task default: [:test]
10
+ task test: [:clean, :rubocop, :spec, :clean, :features, :docs]
11
+ task docs: [:examples, :build_docs, :no_doc_change]
4
12
 
5
13
  RSpec::Core::RakeTask.new(:spec) do |s|
6
14
  s.pattern = 'spec/**/*.rb'
7
15
  end
8
16
 
9
- task :default => :spec
10
- task :test => :spec
17
+ RuboCop::RakeTask.new(:rubocop) do |task|
18
+ task.patterns = ['**/*.rb']
19
+ task.fail_on_error = true
20
+ end
21
+
22
+ Cucumber::Rake::Task.new(:features) do |t|
23
+ t.cucumber_opts = "features --format pretty"
24
+ end
25
+
26
+ task :build_docs do
27
+ pid = fork do
28
+ exec('ruby', 'src_readme/make.rb')
29
+ end
30
+
31
+ Process.wait(pid)
32
+
33
+ if $?.exitstatus > 0
34
+ puts "Readme build failed!"
35
+ exit 1
36
+ end
37
+ end
38
+
39
+ task :no_doc_change do
40
+ pid = fork do
41
+ exec('git', 'diff', '--exit-code', 'src_readme/README_no_output.md')
42
+ end
43
+
44
+ Process.wait(pid)
45
+
46
+ if $?.exitstatus > 0
47
+ puts "Readme build changed the README.md! Must rebuild and commit."
48
+ exit 1
49
+ end
50
+ end
51
+
52
+ task :examples do
53
+ FileList['src_readme/examples/*.rb'].each do |file|
54
+ puts "Testing example: #{file}"
55
+
56
+ pid = fork do
57
+ exec('ruby', file)
58
+ end
59
+ Process.wait(pid)
60
+
61
+ if $?.exitstatus > 0
62
+ puts "Example #{file} failed!"
63
+ exit 1
64
+ end
65
+
66
+ puts ""
67
+ end
68
+ end