quintype-api 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +14 -0
- data/lib/quintype/api.rb +1 -0
- data/lib/quintype/api/client.rb +7 -0
- data/lib/quintype/api/config.rb +1 -1
- data/lib/quintype/api/story.rb +40 -1
- data/lib/quintype/api/tag.rb +19 -0
- data/lib/quintype/api/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ba7e30c793fff129ef3b6fd8d8dbeff37d675ee
|
4
|
+
data.tar.gz: 8861dd6bc1624eec82d3a258c534fe16f96c13dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20a9ed8f6d909d93f1a3cd88a35366798ef30405a372e9b3436986a20337932b08a435abe30074c73c40085d3791390e7fd57fca40b3a0aefceea4c8a80db312
|
7
|
+
data.tar.gz: 1b0295a1b6df43cde1f99daa180ada0a33e28688b5201c4cb26ceb16a9ceae0294ce0d7f44fa3a5aecf56a8428a2af5005af1cb3fef3d7af5a0d967d376e5ac3
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
@@ -2,3 +2,17 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in quintype-api.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem 'rspec', '~> 3.4'
|
8
|
+
end
|
9
|
+
|
10
|
+
group :development, :test do
|
11
|
+
gem 'pry'
|
12
|
+
gem 'byebug'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'vcr'
|
17
|
+
gem 'webmock'
|
18
|
+
end
|
data/lib/quintype/api.rb
CHANGED
data/lib/quintype/api/client.rb
CHANGED
@@ -41,6 +41,13 @@ module Quintype::API
|
|
41
41
|
response.body["story"]
|
42
42
|
end
|
43
43
|
|
44
|
+
def get_tag_by_name(name)
|
45
|
+
response = get("/api/tag/#{name}")
|
46
|
+
return nil if response.status == 404
|
47
|
+
raise ClientException.new("Could not fetch tag", response) unless response.status == 200
|
48
|
+
response.body["tag"]
|
49
|
+
end
|
50
|
+
|
44
51
|
def get_stories(params)
|
45
52
|
response = get("/api/v1/stories", params)
|
46
53
|
raise ClientException.new("Could not get stories", response) unless response.status == 200
|
data/lib/quintype/api/config.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Quintype::API
|
2
|
-
class Config < Base(%w(sketches-host sections layout cdn-name publisher-id story-slug-format cdn-image social-links))
|
2
|
+
class Config < Base(%w(sketches-host sections layout cdn-name publisher-id story-slug-format cdn-image social-links seo-metadata))
|
3
3
|
class << self
|
4
4
|
def get
|
5
5
|
from_hash(Client.instance.get_config)
|
data/lib/quintype/api/story.rb
CHANGED
@@ -1,4 +1,43 @@
|
|
1
1
|
module Quintype::API
|
2
|
+
class StoriesResponse < Struct.new(:params, :stories)
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def each
|
6
|
+
stories.each { |story| yield story }
|
7
|
+
end
|
8
|
+
|
9
|
+
def location
|
10
|
+
return "section-#{params["section-id"]}" if params["section-id"]
|
11
|
+
return "home" if !params["tag"] && !params["section"] && !params["section-name"]
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache_keys(args = {})
|
16
|
+
group_keys(args) + story_keys(args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_liquid
|
20
|
+
stories
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def story_keys(args)
|
25
|
+
publisher_id = args[:publisher_id] || stories[0].publisher_id
|
26
|
+
key_prefix = (args[:soft] == 'stories' || args[:soft] == "all") ? "s" : ""
|
27
|
+
stories.map { |i| "#{key_prefix}s/#{publisher_id}/#{i.id[0..7]}"}
|
28
|
+
end
|
29
|
+
|
30
|
+
def group_keys(args)
|
31
|
+
if location
|
32
|
+
publisher_id = args[:publisher_id] || stories[0].try(:publisher_id)
|
33
|
+
key_prefix = (args[:soft] == 'stories' || args[:soft] == "all") ? "s" : ""
|
34
|
+
["#{key_prefix}q/#{publisher_id}/#{params['story-group']}/#{location}"]
|
35
|
+
else
|
36
|
+
[]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
2
41
|
class StoriesRequest
|
3
42
|
def initialize(klazz, story_group)
|
4
43
|
@klazz = klazz
|
@@ -15,7 +54,7 @@ module Quintype::API
|
|
15
54
|
end
|
16
55
|
|
17
56
|
def from_response(stories)
|
18
|
-
stories.map {|i| @klazz.from_hash(i) }
|
57
|
+
StoriesResponse.new @params, stories.map {|i| @klazz.from_hash(i) }
|
19
58
|
end
|
20
59
|
|
21
60
|
def to_bulk_request
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Quintype::API
|
2
|
+
class Tag < Base(%w(name meta-description))
|
3
|
+
|
4
|
+
def initialize(config, *args)
|
5
|
+
@config = config
|
6
|
+
super(*args)
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def find_by_name(name)
|
12
|
+
response = Client.instance.get_tag_by_name(name)
|
13
|
+
from_hash(response) if response
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/quintype/api/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2016-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- ".rspec"
|
77
78
|
- Gemfile
|
78
79
|
- README.md
|
79
80
|
- Rakefile
|
@@ -89,6 +90,7 @@ files:
|
|
89
90
|
- lib/quintype/api/stack.rb
|
90
91
|
- lib/quintype/api/stack_collection.rb
|
91
92
|
- lib/quintype/api/story.rb
|
93
|
+
- lib/quintype/api/tag.rb
|
92
94
|
- lib/quintype/api/version.rb
|
93
95
|
- quintype-api.gemspec
|
94
96
|
homepage: https://github.com/quintype/quintype-api-ruby
|