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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f34a117063a628c1b37bcf5b201531523e3c4187
4
- data.tar.gz: bb40cd8c20b381d9328213252ca41a14007e83ce
3
+ metadata.gz: 8ba7e30c793fff129ef3b6fd8d8dbeff37d675ee
4
+ data.tar.gz: 8861dd6bc1624eec82d3a258c534fe16f96c13dd
5
5
  SHA512:
6
- metadata.gz: 01c31f71698ddd216bc272c37fa8cda18e204e847ae6b118728e51f30e3d8a66bb8193cd5810358cb190b893856d6238a32186dee796c5264091bbb9de901d03
7
- data.tar.gz: ce2406ec4ef010c73815f4c7dd0e2c3276a9485d1fbf4d65968635e107ac9fca23da14afff72f829dab064f2010945d183ae2ad974a586bb608d9b8e4118d7c9
6
+ metadata.gz: 20a9ed8f6d909d93f1a3cd88a35366798ef30405a372e9b3436986a20337932b08a435abe30074c73c40085d3791390e7fd57fca40b3a0aefceea4c8a80db312
7
+ data.tar.gz: 1b0295a1b6df43cde1f99daa180ada0a33e28688b5201c4cb26ceb16a9ceae0294ce0d7f44fa3a5aecf56a8428a2af5005af1cb3fef3d7af5a0d967d376e5ac3
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
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
@@ -19,6 +19,7 @@ module Quintype
19
19
  autoload :MenuItem, "quintype/api/menu_item"
20
20
  autoload :Stack, "quintype/api/stack"
21
21
  autoload :Story, "quintype/api/story"
22
+ autoload :Tag, "quintype/api/tag"
22
23
 
23
24
  autoload :StackCollection, "quintype/api/stack_collection"
24
25
 
@@ -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
@@ -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)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Quintype
2
2
  module Api
3
- VERSION = "0.1.6"
3
+ VERSION = "0.2.0"
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.6
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-06-29 00:00:00.000000000 Z
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