Class: Juicer
- Inherits:
-
Object
- Object
- Juicer
- Defined in:
- lib/juicer.rb,
lib/juicer/client.rb,
lib/juicer/version.rb
Defined Under Namespace
Classes: Client
Constant Summary collapse
- VERSION =
"1.1.1".freeze
Instance Attribute Summary collapse
-
#client ⇒ Juicer::Client
readonly
The HTTP client for making requests.
Instance Method Summary collapse
-
#article(cps_id) ⇒ Hash
Fetch an article by its CPS_ID.
-
#articles(opts) ⇒ Array<Hash>
Filter/find articles.
-
#formats ⇒ Array<String>
List content formats.
-
#initialize(api_key) ⇒ Juicer
constructor
Initialize the Juicer API client.
-
#products ⇒ Array<String>
List products.
-
#sections ⇒ Array<String>
List sections.
-
#similar_articles(cps_id, opts = {}) ⇒ Array<Hash>
Fetch articles related (similar) to an article.
-
#similar_to(text, opts = {}) ⇒ Array<Hash>
Fetch articles related (similar) to an arbitrary blob of text.
-
#sites ⇒ Array<String>
List sites.
Constructor Details
Instance Attribute Details
#client ⇒ Juicer::Client (readonly)
Returns The HTTP client for making requests.
7 8 9 |
# File 'lib/juicer.rb', line 7 def client @client end |
Instance Method Details
#article(cps_id) ⇒ Hash
Fetch an article by its CPS_ID
76 77 78 |
# File 'lib/juicer.rb', line 76 def article(cps_id) @client.request(:get, "articles/#{cps_id}")["article"] end |
#articles(opts) ⇒ Array<Hash>
The results will include all entities of an article. Therefore, if there are many results, the amount of data transferred is quite large. Just a heads up when doing queries that potentially return a large number of results.
Filter/find articles.
67 68 69 |
# File 'lib/juicer.rb', line 67 def articles(opts) @client.request(:get, "articles", opts)["articles"] end |
#formats ⇒ Array<String>
List content formats.
42 43 44 |
# File 'lib/juicer.rb', line 42 def formats @client.request(:get, "formats")["formats"] end |
#products ⇒ Array<String>
List products.
35 36 37 |
# File 'lib/juicer.rb', line 35 def products @client.request(:get, "products")["products"] end |
#sections ⇒ Array<String>
List sections.
28 29 30 |
# File 'lib/juicer.rb', line 28 def sections @client.request(:get, "sections")["sections"] end |
#similar_articles(cps_id, opts = {}) ⇒ Array<Hash>
Fetch articles related (similar) to an article. Uses tf-idf algorithm to find semantically similar documents.
95 96 97 |
# File 'lib/juicer.rb', line 95 def similar_articles(cps_id, opts = {}) @client.request(:get, "articles/#{cps_id}/similar", opts)["results"] end |
#similar_to(text, opts = {}) ⇒ Array<Hash>
Fetch articles related (similar) to an arbitrary blob of text. Uses tf-idf algorithm to find semantically similar documents.
114 115 116 117 |
# File 'lib/juicer.rb', line 114 def similar_to(text, opts = {}) body = { like_text: URI.encode(text) }.to_json @client.request(:post, "similar_to", opts, body)["results"] end |
#sites ⇒ Array<String>
List sites.
21 22 23 |
# File 'lib/juicer.rb', line 21 def sites @client.request(:get, "sites")["sites"] end |