crema-api-ruby-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 539c41f5531d70d08105841ec87cf6ddce63343e80cd6052441ccfa8a3fd711a
4
+ data.tar.gz: 110471f58c45e683527c54dac505fa7929b196f7ff04e458025a774ee70e901b
5
+ SHA512:
6
+ metadata.gz: 819ef3679d9d80c5176294dd92ddae46d8caf45838937c3b7df890fccd2f9cd71dc0f5a7a21840e6dad76bd67356db2fd7be14eeb8abef9937e91c6304c60f47
7
+ data.tar.gz: 6106ed184ad04cddc56a7dce2a32c68a3c5e386775fa1cee6ffb799a807b168255de0463230a5f7bff7a9e24d3601932864c8795984ee86933a175c1880de1a7
data/lib/crema.rb ADDED
@@ -0,0 +1,10 @@
1
+ require_relative 'crema/version'
2
+ require_relative 'crema/config'
3
+ require_relative 'crema/base'
4
+ require_relative 'crema/oauth'
5
+ require_relative 'crema/client'
6
+ require_relative 'crema/product'
7
+
8
+ module Crema
9
+ HOST = 'https://api.cre.ma'.freeze
10
+ end
data/lib/crema/base.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Crema
5
+ class Base
6
+ def self.connection
7
+ @connection ||= Faraday.new(url: HOST) do |faraday|
8
+ faraday.request :url_encoded
9
+ faraday.adapter Faraday.default_adapter
10
+ end
11
+ end
12
+
13
+ protected
14
+
15
+ def connection
16
+ Crema::Base.connection
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module Crema
2
+ class Client < Base
3
+ def fetch_products(brand_id, page: 1, limit: 30, status: 'selling')
4
+ response = connection.get(
5
+ '/v1/products',
6
+ access_token: Crema.config.access_token,
7
+ brand_id: brand_id,
8
+ page: page,
9
+ limit: limit,
10
+ status: status
11
+ )
12
+ return nil unless response.success?
13
+ JSON.parse(response.body).map { |i| Product.new(i) }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ module Crema
2
+ class Config
3
+ attr_accessor :app_id, :secret, :access_token, :logger
4
+
5
+ def initialize
6
+ reset
7
+ end
8
+
9
+ def reset
10
+ self.app_id = ENV['CREMA_APP_ID']
11
+ self.secret = ENV['CREMA_SECRET']
12
+ self.access_token = ENV['CREMA_ACCESS_TOKEN']
13
+ self.logger = nil
14
+ end
15
+ end
16
+
17
+ class << self
18
+ def configure
19
+ block_given? ? yield(config) : config
20
+ end
21
+
22
+ def config
23
+ @config ||= Config.new
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ module Crema
2
+ class OAuth < Base
3
+ def self.token
4
+ response = connection.post(
5
+ '/oauth/token',
6
+ grant_type: 'client_credentials'.freeze,
7
+ client_id: Crema.config.app_id,
8
+ client_secret: Crema.config.secret
9
+ )
10
+ return nil unless response.success?
11
+ JSON.parse(response.body).dig('access_token')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ module Crema
2
+ class Product
3
+ def initialize(attr)
4
+ @attributes = attr
5
+ end
6
+
7
+ %w[
8
+ id name code org_price final_price product_status display reviews_count
9
+ created_at updated_at
10
+ ].each do |key|
11
+ code = %(
12
+ def #{key}
13
+ @attributes['#{key}']
14
+ end
15
+ )
16
+ class_eval(code, __FILE__, __LINE__)
17
+ end
18
+
19
+ def image_url
20
+ @attributes.dig('image', 'middle_url')
21
+ end
22
+
23
+ def image_width
24
+ @attributes.dig('image', 'middle_width')
25
+ end
26
+
27
+ def image_height
28
+ @attributes.dig('image', 'middle_height')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Crema
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crema-api-ruby-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ashal aka JOKER
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-test
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ description: Crema API Ruby Client Gem
140
+ email:
141
+ - ahastudio@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - lib/crema.rb
147
+ - lib/crema/base.rb
148
+ - lib/crema/client.rb
149
+ - lib/crema/config.rb
150
+ - lib/crema/oauth.rb
151
+ - lib/crema/product.rb
152
+ - lib/crema/version.rb
153
+ homepage: https://github.com/ahastudio/crema-api-ruby-client
154
+ licenses: []
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.7.4
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Crema API Ruby Client
176
+ test_files: []