quintype-api 0.1.0 → 0.1.1

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: 7cc3aac817c35e6ac9cb03b46bdecf715baee374
4
- data.tar.gz: 953311b536e2425d47b3078f403e9ad87f6ad263
3
+ metadata.gz: 9ee80fafd53c61e186022eea442ca903f10f8876
4
+ data.tar.gz: f85fae077dfe1dc1d3de12da8b3b8d7ecc752cb1
5
5
  SHA512:
6
- metadata.gz: e92ee459a05ae48f44d89a74ce77cb20a85cbf11981dd541a00a1f4bb3faab92f47d268729ea86bd9e7b51b0539af315c2486c67608ab07f0d7f544352c4b49c
7
- data.tar.gz: 563a669888533bbcf0e25e90930717e302b7883fa2e561515ed789e026d3259b3d525af2ec27557bfdebc040a2851226f828d658b9b0027929ab31d5012d0fc1
6
+ metadata.gz: 84ab3a04a0f6510089ca4dd90cb166421d97a9d268c8603af90e77c59943588a2957d2c9af8bafa20e03f98da729554f9eb31219b6a1c2185e35238d878d078e
7
+ data.tar.gz: 7f79a049d327243f7c500739acb574a7885aeb4e7885254cde05e8fa515f01b32237c0e0565455e17a572980d0e768e178f3dc7e0edb86222c54f55bf01f7076
@@ -14,8 +14,8 @@ module Quintype::API
14
14
  acc[pair[0]] = pair[1].to_bulk_request
15
15
  acc
16
16
  end
17
- response = Client.instance.post_bulk(requests: requests).body
18
- @responses = response["results"].inject({}) do |acc, pair|
17
+ response = Client.instance.post_bulk(requests)
18
+ @responses = response.inject({}) do |acc, pair|
19
19
  acc[pair[0]] = @requests[pair[0]].from_bulk_response(pair[1])
20
20
  acc
21
21
  end
@@ -29,32 +29,31 @@ module Quintype::API
29
29
  end
30
30
 
31
31
  def get_config
32
- get("/api/v1/config")
32
+ response = get("/api/v1/config")
33
+ raise ClientException.new("Could not get config", response) unless response.status == 200
34
+ response.body
33
35
  end
34
36
 
35
37
  def get_story_by_slug(slug)
36
- get("/api/v1/stories-by-slug", slug: slug)
38
+ response = get("/api/v1/stories-by-slug", slug: slug)
39
+ return nil if response.status == 404
40
+ raise ClientException.new("Could not fetch story", response) unless response.status == 200
41
+ response.body["story"]
37
42
  end
38
43
 
39
44
  def post_bulk(requests)
40
- post("/api/v1/bulk", requests)
45
+ response = post("/api/v1/bulk", requests: requests)
46
+ raise ClientException.new("Could not bulk fetch", response) unless response.status == 200
47
+ response.body["results"]
41
48
  end
42
49
 
43
50
  private
44
51
  def get(url, params = {})
45
- parse_response @conn.get(url, params)
52
+ @conn.get(url, params)
46
53
  end
47
54
 
48
55
  def post(url, body, params = {})
49
- parse_response @conn.post(url, body, params)
50
- end
51
-
52
- def parse_response(response)
53
- if(response.status < 400)
54
- response
55
- else
56
- raise ClientException.new("API returned a non successful response", response)
57
- end
56
+ @conn.post(url, body, params)
58
57
  end
59
58
  end
60
59
  end
@@ -23,7 +23,8 @@ module Quintype::API
23
23
 
24
24
  class << self
25
25
  def find_by_slug(slug)
26
- from_hash(Client.instance.get_story_by_slug(slug).body["story"])
26
+ response = Client.instance.get_story_by_slug(slug)
27
+ from_hash(response) if response
27
28
  end
28
29
 
29
30
  def bulk_stories_request(story_group)
@@ -1,5 +1,5 @@
1
1
  module Quintype
2
2
  module Api
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quintype-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tejas Dinkar