juicer-client 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13438d05877e7471849d931789e96e8e07e7cec6
4
- data.tar.gz: 4e6b4d2ede7e54a1710cb34a03cd3403e974f302
3
+ metadata.gz: 427f04d658cf29b4589b1fb322d51485742b6bb3
4
+ data.tar.gz: 7a1a2aa498ff8beaff557423f7caa996ea9cb3c5
5
5
  SHA512:
6
- metadata.gz: 56dd21d839cb08779bfe8823e4281251193bafd34ae718f34888ff9c55dc4df7aef0b0a5d55393939d5cba33386d1b08a6befad947e1c0bf7981d3c1ba1150b6
7
- data.tar.gz: cd0798958ba81451368e145b4285a1e5f02f605ff2c0aa331a738b294aed8afd348fb40a1b0ba1db50a817b5b3c2db82e9c1230c2ead7311d1255611b7ea27e9
6
+ metadata.gz: 2e7f86ddac59c84017c3bda094fc6689037ea6eef2b7969d59f32c11ecbfaec6560251efc10b39621c6b41ca06ec62378b3845b538da660794882d17fd2206b4
7
+ data.tar.gz: b4b550ea714f5c59c90681ea34c196aca66fcc0568d32cb251689ca85860aa66d96f30930ed5820922bcf045e73f9e400021f8413a1c16d22542e29d7ca66b48
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  The API client for the [BBC News Labs Juicer API](http://juicer.bbcnewslabs.co.uk).
4
4
 
5
+ NOTE: the Juicer is an experiment run by the BBC News Labs. The API may change
6
+ without notice, there are no uptime, reliability guarantees. Please take this
7
+ as experimental sofware in front of experimental API.
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -35,7 +39,8 @@ require 'juicer'
35
39
  juicer = Juicer.new("<your API key>")
36
40
  ```
37
41
 
38
- Have a look at the [documentation](http://bbc-news-labs.github.io/juicer-client/)
42
+ Have a look at the
43
+ [documentation](http://bbc-news-labs.github.io/juicer-client/Juicer.html)
39
44
  for the library on how to filter articles, find similar content, etc.
40
45
 
41
46
  ```ruby
@@ -66,7 +71,6 @@ juicer.similar_articles("news_web_0962731f8c375d5096590ca38cee96e0e408180d")
66
71
  "cps_id"=>"20038835",
67
72
  "created_at"=>"2012-10-23T12:58:45.247Z",
68
73
  "published_at"=>"2012-10-23T11:57:37Z",
69
- "juicer_url"=>"http://juicer.bbcnewslabs.co.uk/articles/20038835.json",
70
74
  "url"=>"http://www.bbc.co.uk/news/business-20038835"},
71
75
  {...}]
72
76
  ```
@@ -8,7 +8,7 @@ class Juicer
8
8
  # Initialize the Juicer API client.
9
9
  #
10
10
  # @param api_key [String] API key obtained from Apigee.
11
- # @return [Juicer] The API client.
11
+ # @return [Juicer] the API client.
12
12
  #
13
13
  def initialize(api_key)
14
14
  @client = Juicer::Client.new(api_key)
@@ -49,10 +49,10 @@ class Juicer
49
49
  # Just a heads up when doing queries that potentially return a large number
50
50
  # of results.
51
51
  #
52
- # @param opts [Hash] A Hash of filter options.
52
+ # @param opts [Hash] a Hash of filter options.
53
53
  # Possible keys are:
54
54
  #
55
- # * `text` - a search term, corresponds to Lucene syntax
55
+ # * `text` - a search term, corresponds to Lucene syntax.
56
56
  # * `product` - list of products to scope to. See {#products}.
57
57
  # * `content_format` - list of content formats to scope to. See {#formats}.
58
58
  # * `section` - list of sections to scope to. See {#sections}.
@@ -79,22 +79,36 @@ class Juicer
79
79
  # find semantically similar documents.
80
80
  #
81
81
  # @param cps_id [String] the `cps_id` of an article.
82
+ # @param opts [Hash] a Hash of query options
83
+ # Possible keys are:
84
+ #
85
+ # * `size` - how many results to return. Results are ordered by their
86
+ # "match" score, i.e how similar they are to a given article, and the
87
+ # top `size` results are returned.
88
+ # * `product` - an [Array] of products to scope to. See {#products}.
82
89
  # @return [Array<Hash>] list of similar articles. Currently capped to 10 most
83
90
  # similar.
84
91
  #
85
- def similar_articles(cps_id)
86
- @client.request(:get, "articles/#{cps_id}/similar")["results"]
92
+ def similar_articles(cps_id, opts = {})
93
+ @client.request(:get, "articles/#{cps_id}/similar", opts)["results"]
87
94
  end
88
95
 
89
96
  # Fetch articles related (similar) to an arbitrary blob of text. Uses tf-idf
90
97
  # algorithm to find semantically similar documents.
91
98
  #
92
99
  # @param text [String] a blob of text.
100
+ # @param opts [Hash] a Hash of query options
101
+ # Possible keys are:
102
+ #
103
+ # * `size` - how many results to return. Results are ordered by their
104
+ # "match" score, i.e how similar they are to the given blob of text, and
105
+ # the top `size` results are returned.
106
+ # * `product` - an [Array] of products to scope to. See {#products}.
93
107
  # @return [Array<Hash>] list of similar articles. Currently capped to 10 most
94
108
  # similar.
95
109
  #
96
- def similar_to(text)
110
+ def similar_to(text, opts = {})
97
111
  body = { like_text: URI.encode(text) }.to_json
98
- @client.request(:post, "similar_to", {}, body)["results"]
112
+ @client.request(:post, "similar_to", opts, body)["results"]
99
113
  end
100
114
  end
@@ -18,8 +18,8 @@ class Juicer
18
18
 
19
19
  # Initialize HTTP client
20
20
  #
21
- # @param api_key [String] the API key from Apigee
22
- # @return [Juicer::Client] HTTP client instance
21
+ # @param api_key [String] the API key from Apigee.
22
+ # @return [Juicer::Client] HTTP client instance.
23
23
  #
24
24
  def initialize(api_key)
25
25
  @api_key = api_key
@@ -33,7 +33,7 @@ class Juicer
33
33
  # @note The Juicer API currently only supports `:get` and `:post` values for
34
34
  # the `method` param.
35
35
  # @param method [Symbol] HTTP method.
36
- # @param path [String] an endpoint path
36
+ # @param path [String] an endpoint path.
37
37
  # @param query_params [Hash] a hash of query parameters. List values are
38
38
  # handled "correctly" in the sense that values of [Array] type produce
39
39
  # `key[]=foo&key[]=bar` style values, suitable for Rails.
@@ -54,8 +54,8 @@ class Juicer
54
54
 
55
55
  # Small helper method for sanitizing the `path` for `request` method.
56
56
  #
57
- # @param path [String] a path to an endpoint
58
- # @return [String] sanitized and fully constructed endpoint URL
57
+ # @param path [String] a path to an endpoint.
58
+ # @return [String] sanitized and fully constructed endpoint URL.
59
59
  #
60
60
  def api_url(path)
61
61
  path.sub!(/^\/+/, '')
@@ -1,3 +1,3 @@
1
1
  class Juicer
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
@@ -124,12 +124,28 @@ describe Juicer do
124
124
  stub_request(:get, "http://data.bbc.co.uk/bbcrd-juicer/articles/#{cps_id}/similar.json")
125
125
  .with(query: { apikey: api_key })
126
126
  .to_return(body: body.to_json)
127
+ stub_request(:get, "http://data.bbc.co.uk/bbcrd-juicer/articles/#{cps_id}/similar.json")
128
+ .with(query: { apikey: api_key, size: 5 })
129
+ .to_return(body: body.to_json)
130
+ stub_request(:get, "http://data.bbc.co.uk/bbcrd-juicer/articles/#{cps_id}/similar.json")
131
+ .with(query: { apikey: api_key, product: ["NewsWeb"] })
132
+ .to_return(body: body.to_json)
127
133
  end
128
134
 
129
- it "queries the `similar` endpoint" do
135
+ it "queries the `similar` endpoint with defaults" do
130
136
  response = juicer.similar_articles(cps_id)
131
137
  expect(response).to eq(body["results"])
132
138
  end
139
+
140
+ it "queries the `similar` endpoint with `size`" do
141
+ response = juicer.similar_articles(cps_id, size: 5)
142
+ expect(response).to eq(body["results"])
143
+ end
144
+
145
+ it "queries the `similar` endpoint with `product`" do
146
+ response = juicer.similar_articles(cps_id, product: ["NewsWeb"])
147
+ expect(response).to eq(body["results"])
148
+ end
133
149
  end
134
150
 
135
151
  describe "#similar_to" do
@@ -144,11 +160,29 @@ describe Juicer do
144
160
  .with(query: { apikey: api_key },
145
161
  body: { like_text: URI.encode(text) }.to_json)
146
162
  .to_return(body: body.to_json)
163
+ stub_request(:post, "http://data.bbc.co.uk/bbcrd-juicer/similar_to.json")
164
+ .with(query: { apikey: api_key, size: 5 },
165
+ body: { like_text: URI.encode(text) }.to_json)
166
+ .to_return(body: body.to_json)
167
+ stub_request(:post, "http://data.bbc.co.uk/bbcrd-juicer/similar_to.json")
168
+ .with(query: { apikey: api_key, product: ["NewsWeb"] },
169
+ body: { like_text: URI.encode(text) }.to_json)
170
+ .to_return(body: body.to_json)
147
171
  end
148
172
 
149
- it "queries the `similar_to` endpoint" do
173
+ it "queries the `similar_to` endpoint with defaults" do
150
174
  response = juicer.similar_to(text)
151
175
  expect(response).to eq(body["results"])
152
176
  end
177
+
178
+ it "queries the `similar_to` endpoint with `size`" do
179
+ response = juicer.similar_to(text, size: 5)
180
+ expect(response).to eq(body["results"])
181
+ end
182
+
183
+ it "queries the `similar_to` endpoint with `product`" do
184
+ response = juicer.similar_to(text, product: ["NewsWeb"])
185
+ expect(response).to eq(body["results"])
186
+ end
153
187
  end
154
188
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: juicer-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Sutt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpi