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 +4 -4
- data/lib/quintype/api/bulk.rb +2 -2
- data/lib/quintype/api/client.rb +12 -13
- data/lib/quintype/api/story.rb +2 -1
- data/lib/quintype/api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ee80fafd53c61e186022eea442ca903f10f8876
|
4
|
+
data.tar.gz: f85fae077dfe1dc1d3de12da8b3b8d7ecc752cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84ab3a04a0f6510089ca4dd90cb166421d97a9d268c8603af90e77c59943588a2957d2c9af8bafa20e03f98da729554f9eb31219b6a1c2185e35238d878d078e
|
7
|
+
data.tar.gz: 7f79a049d327243f7c500739acb574a7885aeb4e7885254cde05e8fa515f01b32237c0e0565455e17a572980d0e768e178f3dc7e0edb86222c54f55bf01f7076
|
data/lib/quintype/api/bulk.rb
CHANGED
@@ -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
|
18
|
-
@responses = response
|
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
|
data/lib/quintype/api/client.rb
CHANGED
@@ -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
|
-
|
52
|
+
@conn.get(url, params)
|
46
53
|
end
|
47
54
|
|
48
55
|
def post(url, body, params = {})
|
49
|
-
|
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
|
data/lib/quintype/api/story.rb
CHANGED
@@ -23,7 +23,8 @@ module Quintype::API
|
|
23
23
|
|
24
24
|
class << self
|
25
25
|
def find_by_slug(slug)
|
26
|
-
|
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)
|
data/lib/quintype/api/version.rb
CHANGED