vtex 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e42153c814c60f7b91bb8af9191a6fbe900020b
4
+ data.tar.gz: 515477e7229022f6316f9606581f95ccd61c53d9
5
+ SHA512:
6
+ metadata.gz: ffcf04b2e79513c9b8eb8124f5fb7ebabbf73e8ba09fc4c1d91505e01ba61e4dcdff6c9cf72be67d80defb8edb4daa745a1df0993eed2fb3bc34d25de01d3778
7
+ data.tar.gz: 902f0e105611e1f3ed56fa06c98ec1296ef07f7c786b28fd0bb8a470f9edfe6886475ea57ca9f5c1ba1b014487c6743276a5d7af93c9f20f2ff9c626409ced3a
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install:
6
+ - gem install bundler -v 1.15.3
7
+ script:
8
+ - bundle exec rspec ./spec
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'simplecov'
6
+ gem 'activesupport'
7
+
8
+ gemspec
9
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Mumo Carlos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,110 @@
1
+ # Vtex
2
+
3
+ Vtex API client ruby implementation
4
+
5
+ [![Build Status](https://travis-ci.org/mumoc/vtex.svg?branch=master)](https://travis-ci.org/mumoc/vtex)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vtex'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vtex
22
+
23
+
24
+ ## Usage
25
+
26
+ You'll need to gatter the following information from your VTex account
27
+
28
+ - **X-VTEX-API-AppKey**
29
+
30
+ Email from a user with access to the API.
31
+
32
+ - **X-VTEX-API-AppToken**
33
+
34
+ VTEXId password of the user with access to the API.
35
+
36
+ - **Account name**
37
+
38
+ VTex account name.
39
+
40
+ - **Environment**:
41
+ - Use `vtexcommercestable` for production
42
+ - Use `vtexcommmercebeta` for tests
43
+
44
+ *Note: It's recommended that you create an specific user to access the API ([vtex-auth](http://help.vtex.com/en/faq/how-do-you-authenticate-in-the-api))*
45
+
46
+
47
+ With all the information retrieve a client instance with it.
48
+
49
+ ```ruby
50
+ client = Vtex::Client.new({ account_name: "demo",
51
+ environment: "vtexcommercebeta",
52
+ app_key: "api.user@email.com",
53
+ app_token: "VTEXIdPassword" })
54
+ ```
55
+
56
+ ## Design
57
+
58
+ VTex follows a design of resources as methods on the client. For example, for Products, you will call your client like this:
59
+
60
+ ```ruby
61
+ client = Vtex::Client.new({ ... })
62
+ client.products #=> ProductsResource
63
+
64
+ ```
65
+
66
+ VTex will return PORO objects that contain the information provided by the API. For example:
67
+
68
+ ```ruby
69
+ client.products.by_id(id: 1)
70
+ # => Vtex::Product (Id:1, Name: "Guarda-Roupa Casal Lisboa 10 Portas 3 Gavetas - Araplac", ...)
71
+ ```
72
+
73
+ *Note: Right now, Key Values are being used as they come from the API*
74
+
75
+ # All Resources and actions.
76
+
77
+ All resources, methods and properties are direct matches from the [VTex API](http://help.vtex.com/en/developer-docs)
78
+
79
+ ## Products resource
80
+
81
+ Vtex API: [Catalog System - Product](https://documenter.getpostman.com/view/845/catalogsystem-102/Hs44#ee16e494-d3b0-36f0-cfed-219aef3f155e)
82
+
83
+ **Usage:**
84
+
85
+ ```ruby
86
+ client = Vtex::Client.new({ ... })
87
+ client.products #=> ProductsResource
88
+ ```
89
+
90
+ **Actions supported:**
91
+
92
+ * `client.products.by_id(id: 'id')`
93
+
94
+ ## Development
95
+
96
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
97
+
98
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
99
+
100
+ ## Contributing
101
+
102
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mumoc/vtex. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
103
+
104
+ ## License
105
+
106
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
107
+
108
+ ## Code of Conduct
109
+
110
+ Everyone interacting in the Vtex project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mumoc/vtex/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vtex"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require "vtex/version"
2
+ require "active_support/all"
3
+ require "resource_kit"
4
+ require "kartograph"
5
+
6
+ module Vtex
7
+ autoload :Client, "vtex/client"
8
+
9
+ # Models
10
+ autoload :Base, 'vtex/models/base'
11
+ autoload :Product, 'vtex/models/product'
12
+
13
+ # Resources
14
+ autoload :ProductResource, "vtex/resources/product_resource"
15
+
16
+ # Mappings
17
+ autoload :ProductMapping, "vtex/mappings/product_mapping"
18
+ end
@@ -0,0 +1,61 @@
1
+ require 'faraday'
2
+
3
+ module Vtex
4
+ class Client
5
+ VTEX_API_BASE = "http://accountName.environment.com.br"
6
+
7
+ attr_reader :account_name, :environment, :app_key, :app_token
8
+
9
+ def initialize(options = {})
10
+ @account_name = options[:account_name]
11
+ @environment = options[:environment]
12
+ @app_key = options[:app_key]
13
+ @app_token = options[:app_token]
14
+ end
15
+
16
+ def connection
17
+ @faraday ||= Faraday.new connection_options do |request|
18
+ request.adapter :net_http
19
+ end
20
+ end
21
+
22
+ def self.resources
23
+ {
24
+ products: ProductResource
25
+ }
26
+ end
27
+
28
+ def method_missing(name, *args, &block)
29
+ if self.class.resources.keys.include?(name)
30
+ resources[name] ||= self.class.resources[name].new(connection: connection)
31
+ resources[name]
32
+ else
33
+ super
34
+ end
35
+ end
36
+
37
+ def resources
38
+ @resources ||= {}
39
+ end
40
+
41
+ private
42
+
43
+ def vtex_api
44
+ VTEX_API_BASE.gsub(/accountName|environment/,
45
+ 'accountName' => account_name,
46
+ 'environment' => environment)
47
+ end
48
+
49
+ def connection_options
50
+ {
51
+ url: vtex_api,
52
+ headers: {
53
+ content_type: 'application/json',
54
+ "X-VTEX-API-AppKey" => app_key,
55
+ "X-VTEX-API-AppToken" => app_token
56
+ }
57
+ }
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,31 @@
1
+ module Vtex
2
+ class ProductMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping Product
7
+
8
+ property :Id, scopes: [:read]
9
+ property :Name, scopes: [:read]
10
+ property :DepartmentId, scopes: [:read]
11
+ property :CategoryId, scopes: [:read]
12
+ property :BrandId, scopes: [:read]
13
+ property :LinkId, scopes: [:read]
14
+ property :RefId, scopes: [:read]
15
+ property :IsVisible, scopes: [:read]
16
+ property :Description, scopes: [:read]
17
+ property :DescriptionShort, scopes: [:read]
18
+ property :ReleaseDate, scopes: [:read]
19
+ property :KeyWords, scopes: [:read]
20
+ property :Title, scopes: [:read]
21
+ property :IsActive, scopes: [:read]
22
+ property :TaxCode, scopes: [:read]
23
+ property :MetaTagDescription, scopes: [:read]
24
+ property :SupplierId, scopes: [:read]
25
+ property :ShowWithoutStock, scopes: [:read]
26
+ property :ListStoreId, scopes: [:read]
27
+ property :AdWordsRemarketingCode, scopes: [:read]
28
+ property :LomadeeCampaignCode, scopes: [:read]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ require 'virtus'
2
+
3
+ module Vtex
4
+ class Base
5
+ include Virtus.model
6
+ include Virtus::Equalizer.new(name || inspect)
7
+
8
+ def inspect
9
+ values = Hash[instance_variables.map { |name| [name, instance_variable_get(name)] } ]
10
+ "<#{self.class.name} #{values}>"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module Vtex
2
+ class Product < Base
3
+ [:Id, :Name, :DepartmentId, :CategoryId, :BrandId, :LinkId, :RefId, :IsVisible,
4
+ :Description, :DescriptionShort, :ReleaseDate, :KeyWords, :Title, :IsActive,
5
+ :TaxCode, :MetaTagDescription, :SupplierId, :ShowWithoutStock, :ListStoreId,
6
+ :AdWordsRemarketingCode, :LomadeeCampaignCode].each do |key|
7
+ attribute(key)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Vtex
2
+ class ProductResource < ResourceKit::Resource
3
+ resources do
4
+ action :by_id, 'GET /api/catalog_system/pvt/products/ProductGet/:id' do
5
+ handler(200) { |response| ProductMapping.extract_single(response.body, :read) }
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,3 @@
1
+ module Vtex
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "vtex/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vtex"
8
+ spec.version = Vtex::VERSION
9
+ spec.authors = ["Mumo Carlos"]
10
+ spec.email = ["mumo.crls@gmail.com"]
11
+
12
+ spec.summary = %q{Gem to wrap VTex API}
13
+ spec.description = %q{Gem to wrap VTex API}
14
+ spec.homepage = "https://github.com/mumoc/vtex"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency 'virtus'
25
+ spec.add_dependency "resource_kit"
26
+ spec.add_dependency "kartograph"
27
+ spec.add_dependency "activesupport"
28
+ spec.add_dependency "faraday"
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.15"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+
34
+ # FakeServe
35
+ spec.add_development_dependency 'sinatra'
36
+ spec.add_development_dependency 'webmock'
37
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vtex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mumo Carlos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: virtus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: resource_kit
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: kartograph
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sinatra
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Gem to wrap VTex API
154
+ email:
155
+ - mumo.crls@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/setup
169
+ - lib/vtex.rb
170
+ - lib/vtex/client.rb
171
+ - lib/vtex/mappings/product_mapping.rb
172
+ - lib/vtex/models/base.rb
173
+ - lib/vtex/models/product.rb
174
+ - lib/vtex/resources/product_resource.rb
175
+ - lib/vtex/version.rb
176
+ - vtex.gemspec
177
+ homepage: https://github.com/mumoc/vtex
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.6.8
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Gem to wrap VTex API
201
+ test_files: []