File tree Expand file tree Collapse file tree 6 files changed +77
-13
lines changed
Expand file tree Collapse file tree 6 files changed +77
-13
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ Gem::Specification.new do |spec|
3838 spec . add_development_dependency 'rspec' , '~> 3.5'
3939 spec . add_development_dependency 'vcr' , '~> 3.0' , '>= 3.0.3'
4040 spec . add_development_dependency 'awesome_print'
41+ spec . add_development_dependency 'rb-readline'
42+ spec . add_development_dependency 'byebug'
4143 spec . add_development_dependency 'webmock' , '~> 2.3' , '>= 2.3.1'
4244 spec . add_development_dependency 'dotenv' , '~> 2.1' , '>= 2.1.1'
4345 spec . add_development_dependency 'yard'
Original file line number Diff line number Diff line change 1+ require_relative 'entry'
2+
3+ module Contentstack
4+ class Entries
5+ include Enumerable
6+
7+ attr_reader :body , :entries
8+
9+ def initialize ( body )
10+ @body = body
11+ @entries = body . map { |entry | Entry . new ( entry ) }
12+ end
13+
14+ def each ( &block )
15+ entries . each ( &block )
16+ end
17+ end
18+ end
Original file line number Diff line number Diff line change 1+
2+
3+ module Contentstack
4+ class Entry
5+
6+ def initialize ( attributes )
7+ @attributes = attributes
8+ end
9+
10+ def properties
11+ @attributes . keys
12+ end
13+
14+ def is_entry?
15+ true
16+ end
17+ end
18+ end
Original file line number Diff line number Diff line change 1+ require "byebug"
2+
3+ module Contentstack
4+ class Query
5+ attr_reader :data
6+
7+ def initialize ( data , query )
8+ @data = data
9+ @query = query
10+ end
11+
12+ def all
13+ data
14+ end
15+
16+ end
17+ end
Original file line number Diff line number Diff line change 1- require_relative "response"
21
32require 'typhoeus'
43
54module Contentstack
65 class Request
76
8- attr_reader :endpoint
7+ attr_reader :endpoint , :client
98
10- def initialize ( client , endpoint )
9+ def initialize ( client , endpoint , query = { } )
1110 # puts endpoint
1211 @client = client
1312 @endpoint = endpoint
13+
14+ @query = ( normalize_query ( query ) if query && !query . empty? )
1415 end
1516
17+ # Delegates the actual HTTP work to the client
1618 def fetch
17- response = Typhoeus ::Request . new (
18- endpoint ,
19- headers : {
20- api_key : @client . headers [ :api_key ] ,
21- access_token : @client . headers [ :access_token ] ,
22- accept_encoding : "gzip" }
23- ) . run
24-
25- Response . new ( response . body )
19+ client . fetch ( self )
20+ end
21+
22+ private
23+
24+ def normalize_query ( query )
25+ Hash [
26+ query . map do |key , value |
27+ [
28+ key . to_sym ,
29+ value . is_a? ( ::Array ) ? value . join ( ',' ) : value
30+ ]
31+ end
32+ ]
2633 end
2734
2835 end
Original file line number Diff line number Diff line change 11require "multi_json"
2+ require_relative 'entries'
23
34module Contentstack
45
@@ -15,7 +16,7 @@ def initialize(body)
1516 end
1617
1718 def entries
18- @body [ :entries ]
19+ Entries . new ( @body [ :entries ] )
1920 end
2021
2122 def content_types
@@ -37,6 +38,7 @@ def assets
3738 def asset
3839 @body [ :asset ]
3940 end
41+
4042 end
4143
4244end
You can’t perform that action at this time.
0 commit comments