quintype-api 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23a459e63fd980b2e96a9f2ad438ee3b6849fd47
4
- data.tar.gz: 3b21f84d4ca011a393789ca209e1ec47359e089b
3
+ metadata.gz: 33d8f416309a11bd511f6d8e97fbca7fecc9ac57
4
+ data.tar.gz: 1386af307d5441ac4867206cf74989ca857a1f0a
5
5
  SHA512:
6
- metadata.gz: 09b3c7abaf55dda939acfb879c5f165ae62165a330d5eccaaefaa58cbc9ec9f9ad6a860e50f694f95e62fbb6b0c9775189d27dcee645638d8f764d4935e0fd50
7
- data.tar.gz: 138ab8ca7a14b2d1ed0a66cf2d69e35f6f7fa14b84016ee9a3c91151d8271ed5220ec931313acb1538b8f592b933681d8bd9f270a70e7aa8c3cb5794bf95e5db
6
+ metadata.gz: a924dfb0b0befb27c1459d26a357afc3e1466465d5beae6307c7ac4f07e85a0976cd0fb64ac2f1872a9664ef17a8230337dc410cbcd9a438dbe68c975d94346b
7
+ data.tar.gz: 64644f757db104a16fecb780459bea472825bdae3caa708827659e995ad03fdb2dd3fc6ad81cc7295cd93ab0b79659c9a2d79333400952ada704d319c17783eb
data/README.md CHANGED
@@ -54,6 +54,19 @@ QtConfig.get.sections
54
54
  Story.find_by_slug("5-timeless-truths-from-the-serenity-prayer-that-offer-wisdom")
55
55
  ```
56
56
 
57
+ ### Fetching an group of story
58
+ ```ruby
59
+ stories = Story.fetch('top', section: "Politics")
60
+ ```
61
+
62
+ ### Searching for stories
63
+
64
+ ```ruby
65
+ stories = Story.search(q: "Peter")
66
+ stories.map {|i| i.headline }
67
+ p stories.total
68
+ ```
69
+
57
70
  ### Bulk Fetching stories
58
71
 
59
72
  ```ruby
@@ -75,4 +88,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
75
88
  ## Contributing
76
89
 
77
90
  Bug reports and pull requests are welcome on GitHub at https://github.com/quintype/quintype-api-ruby.
78
-
@@ -41,6 +41,18 @@ module Quintype::API
41
41
  response.body["story"]
42
42
  end
43
43
 
44
+ def get_stories(params)
45
+ response = get("/api/v1/stories", params)
46
+ raise ClientException.new("Could not get stories", response) unless response.status == 200
47
+ response.body["stories"]
48
+ end
49
+
50
+ def get_search(params)
51
+ response = get("/api/v1/search", params)
52
+ raise ClientException.new("Could not search stories", response) unless response.status == 200
53
+ response.body["results"]
54
+ end
55
+
44
56
  def post_bulk(requests)
45
57
  response = post("/api/v1/bulk", requests: requests)
46
58
  raise ClientException.new("Could not bulk fetch", response) unless response.status == 200
@@ -10,12 +10,44 @@ module Quintype::API
10
10
  self
11
11
  end
12
12
 
13
+ def execute!
14
+ from_response(Client.instance.get_stories(@params))
15
+ end
16
+
17
+ def from_response(stories)
18
+ stories.map {|i| @klazz.from_hash(i) }
19
+ end
20
+
13
21
  def to_bulk_request
14
22
  @params.merge(_type: "stories")
15
23
  end
16
24
 
17
25
  def from_bulk_response(response)
18
- response["stories"].map {|i| @klazz.from_hash(i) }
26
+ from_response(response["stories"])
27
+ end
28
+ end
29
+
30
+ class SearchResults < Base(:from, :size, :total, :stories)
31
+ include Enumerable
32
+
33
+ def each
34
+ stories.each { |i| yield i }
35
+ end
36
+ end
37
+
38
+ class SearchRequest
39
+ def initialize(klazz, params)
40
+ @klazz = klazz
41
+ @params = params
42
+ end
43
+
44
+ def execute!
45
+ from_response(Client.instance.get_search(@params))
46
+ end
47
+
48
+ def from_response(response)
49
+ mapped_stories = response["stories"].map { |i| @klazz.from_hash(i) }
50
+ SearchResults.from_hash(response.merge("stories" => mapped_stories))
19
51
  end
20
52
  end
21
53
 
@@ -30,6 +62,14 @@ module Quintype::API
30
62
  def bulk_stories_request(story_group)
31
63
  StoriesRequest.new(self, story_group)
32
64
  end
65
+
66
+ def fetch(story_group, options = {})
67
+ StoriesRequest.new(self, story_group).add_params(options).execute!
68
+ end
69
+
70
+ def search(options)
71
+ SearchRequest.new(self, options).execute!
72
+ end
33
73
  end
34
74
  end
35
75
  end
@@ -1,5 +1,5 @@
1
1
  module Quintype
2
2
  module Api
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quintype-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tejas Dinkar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-30 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.2.2
113
+ rubygems_version: 2.5.1
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Ruby Gem to Access the Quintype API