trustvox 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
+ SHA1:
3
+ metadata.gz: c5601ab2d9f8aee9f51484e788027dea65eedaf9
4
+ data.tar.gz: 4bbe76cd281c9d059f52efba9183ea07323ff300
5
+ SHA512:
6
+ metadata.gz: 46b4f5cf632b3dd0bd2368f73bd7246ce4494dfc105c6f7970b5eded82de541e11c966a1b7ca2ce71da9b3c237a92772da83f841538c5d6748d6bc85ae906665
7
+ data.tar.gz: 74fa242dde0cedcb3879d8b608857c336acb9ebbb9a7ca04e928d6c992716eab7a994e47f2c0b84bd45fbf3fb610eaf752bb7fe4e177582ab94b1841cc6a73e1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in trustvox.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ trustvox (0.1.0)
5
+ httparty (~> 0.16)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ concurrent-ruby (1.0.5)
11
+ diff-lcs (1.3)
12
+ dotenv (2.2.1)
13
+ faker (1.8.7)
14
+ i18n (>= 0.7)
15
+ httparty (0.16.1)
16
+ multi_xml (>= 0.5.2)
17
+ i18n (1.0.0)
18
+ concurrent-ruby (~> 1.0)
19
+ multi_xml (0.6.0)
20
+ rake (10.5.0)
21
+ rspec (3.7.0)
22
+ rspec-core (~> 3.7.0)
23
+ rspec-expectations (~> 3.7.0)
24
+ rspec-mocks (~> 3.7.0)
25
+ rspec-core (3.7.1)
26
+ rspec-support (~> 3.7.0)
27
+ rspec-expectations (3.7.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.7.0)
30
+ rspec-mocks (3.7.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.7.0)
33
+ rspec-support (3.7.1)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.16)
40
+ dotenv
41
+ faker (~> 1.8.7)
42
+ rake (~> 10.0)
43
+ rspec (~> 3.7)
44
+ trustvox!
45
+
46
+ BUNDLED WITH
47
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Bruno Frank
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Bruno Frank
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.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Trustvox
2
+
3
+ Gem to send interact with Trustvox API.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'trustvox'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install trustvox
18
+
19
+ ## Usage
20
+
21
+ Set your credentials
22
+
23
+ ```ruby
24
+ Trustvox::Config.token = 'PLATFORM TOKEN'
25
+ Trustvox::Config.store_token = 'STORE TOKEN'
26
+ Trustvox::Config.store_id = 'STORE ID'
27
+ ```
28
+
29
+ Or througth ENV vars.
30
+
31
+ ```sh
32
+ TRUSTVOX_ACCESS_TOKEN='PLATFORM TOKEN'
33
+ TRUSTVOX_STORE_TOKEN='STORE TOKEN'
34
+ TRUSTVOX_STORE_ID='STORE ID'
35
+ ```
36
+
37
+ Push order information.
38
+
39
+ ```ruby
40
+ order = Trustvox::Store.new.push_order({
41
+ order_id: 1,
42
+ delivery_date: DateTime.now.to_s,
43
+ client: {
44
+ first_name: 'Homer',
45
+ last_name: 'Simpson',
46
+ email: 'homer@fox.com',
47
+ },
48
+ items: [{
49
+ id: 1,
50
+ url: 'http://www.fox.com/donut',
51
+ name: 'Donut',
52
+ price: 2.99,
53
+ photos_urls: ["http://store.fox.com/donut.png"],
54
+ }]
55
+ })
56
+
57
+ order.inspect
58
+
59
+ {:status=>201, :data=>{"tags"=>[], "order_id"=>1, "client"=>{"tags"=>[], "first_name"=>"Homer", "last_name"=>"Simpson", "email"=>"homer@fox.com"}, "delivery_date"=>"2018-04-03", "items"=>[{"id"=>"1", "name"=>"Donut", "url"=>"http://www.fox.com/donut", "price"=>"2.99", "tags"=>[]}]}}
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/brunofrank/trustvox.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trustvox"
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__)
data/bin/setup ADDED
@@ -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,28 @@
1
+ require 'httparty'
2
+
3
+ module Trustvox
4
+ # Base class for all api request
5
+ class Base
6
+ include HTTParty
7
+
8
+ headers 'Accept': 'application/vnd.trustvox.com; version=1',
9
+ 'Content-Type': 'application/json'
10
+ debug_output $stdout
11
+ def initialize
12
+ if Config.is_on_staging?
13
+ self.class.base_uri 'http://staging.trustvox.com.br/api'
14
+ seld.class.debug_output $stdout
15
+ else
16
+ self.class.base_uri 'http://trustvox.com.br/api'
17
+ end
18
+ end
19
+
20
+ def auth_by_platform_token!
21
+ self.class.headers 'Authorization': "token #{Config.token}"
22
+ end
23
+
24
+ def auth_by_store_token!
25
+ self.class.headers 'Authorization': "token #{Config.store_token}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,44 @@
1
+ module Trustvox
2
+ # Responsible to hold api's access token
3
+ class Config
4
+ @store_id = nil
5
+ @token = nil
6
+ @staging = false
7
+
8
+ def self.store_id=(value)
9
+ @store_id = value
10
+ end
11
+
12
+ def self.store_id
13
+ @store_id || ENV['TRUSTVOX_STORE_ID']
14
+ end
15
+
16
+ def self.token=(value)
17
+ @token = value
18
+ end
19
+
20
+ def self.token
21
+ @token || ENV['TRUSTVOX_ACCESS_TOKEN']
22
+ end
23
+
24
+ def self.store_token=(value)
25
+ @store_token = value
26
+ end
27
+
28
+ def self.store_token
29
+ @store_token || ENV['TRUSTVOX_STORE_TOKEN']
30
+ end
31
+
32
+ def self.is_on_staging?
33
+ @staging
34
+ end
35
+
36
+ def self.staging!
37
+ @staging = true
38
+ end
39
+
40
+ def self.production!
41
+ @staging = false
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ module Trustvox
2
+ # Responsible to api calls about store
3
+ class Store < Base
4
+
5
+ # Call create store api
6
+ # @param store_data
7
+ def create(store_data)
8
+ auth_by_platform_token!
9
+ response = self.class.post('/stores', { body: store_data.to_json })
10
+ data = JSON.parse(response.body) rescue nil
11
+
12
+ {
13
+ status: response.code,
14
+ data: data,
15
+ }
16
+ end
17
+
18
+ # Call order api
19
+ # @param order_data
20
+ def push_order(order_data)
21
+ body = Utils.build_push_order_data(order_data)
22
+ auth_by_store_token!
23
+ response = self.class.post("/stores/#{Config.store_id}/orders", { body: body.to_json })
24
+ data = JSON.parse(response.body) rescue nil
25
+
26
+ { status: response.code, data: data }
27
+ end
28
+
29
+ # Call store lookup api
30
+ # @param url
31
+ def load_store(url)
32
+ auth_by_platform_token!
33
+ response = self.class.get("/stores", { query: { url: url} })
34
+ data = JSON.parse(response.body) rescue nil
35
+
36
+ {
37
+ status: response.code,
38
+ data: data,
39
+ }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ module Trustvox
2
+ # Responsible to api calls about store
3
+ class Utils
4
+ DEFAULT_ORDER = {
5
+ order_id: nil,
6
+ delivery_date: nil,
7
+ client: {},
8
+ items: [],
9
+ tags: []
10
+ }
11
+
12
+ DEFAULT_ORDER_ITEM = {
13
+ id: nil,
14
+ url: nil,
15
+ name: nil,
16
+ price: nil,
17
+ photos_urls: [],
18
+ tags: [],
19
+ extra: {}
20
+ }
21
+
22
+ DEFAULT_CLIENT = {
23
+ first_name: nil,
24
+ last_name: nil,
25
+ email: nil,
26
+ tags: []
27
+ }
28
+
29
+ def self.build_push_order_data(order_data)
30
+ body = DEFAULT_ORDER.merge(order_data)
31
+
32
+ body[:items] = order_data[:items].map do |item|
33
+ DEFAULT_ORDER_ITEM.merge(item)
34
+ end
35
+
36
+ body[:client] = DEFAULT_CLIENT .merge(order_data[:client])
37
+
38
+ body
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Trustvox
2
+ VERSION = "0.1.0"
3
+ end
data/lib/trustvox.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "trustvox/version"
2
+ require "trustvox/utils"
3
+ require "trustvox/config"
4
+ require "trustvox/base"
5
+ require "trustvox/store"
6
+
7
+ # Main gem module
8
+ module Trustvox
9
+ # Silence is golden!
10
+ end
data/trustvox.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "trustvox/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trustvox"
8
+ spec.version = Trustvox::VERSION
9
+ spec.authors = ["Bruno Frank"]
10
+ spec.email = ["bfscordeiro@gmail.com"]
11
+
12
+ spec.summary = %q{Gem for Trustvox API access.}
13
+ spec.description = %q{This gem is used to acess the Trustvox api, create stores, send orders and etc.}
14
+ spec.homepage = "https://github.com/brunofrank/trustvox"
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 = "bin"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.7"
27
+ spec.add_development_dependency "faker", "~> 1.8.7"
28
+ spec.add_development_dependency "dotenv"
29
+ spec.add_runtime_dependency "httparty", "~> 0.16"
30
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trustvox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bruno Frank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faker
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.7
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.7
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: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.16'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.16'
97
+ description: This gem is used to acess the Trustvox api, create stores, send orders
98
+ and etc.
99
+ email:
100
+ - bfscordeiro@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/trustvox.rb
117
+ - lib/trustvox/base.rb
118
+ - lib/trustvox/config.rb
119
+ - lib/trustvox/store.rb
120
+ - lib/trustvox/utils.rb
121
+ - lib/trustvox/version.rb
122
+ - trustvox.gemspec
123
+ homepage: https://github.com/brunofrank/trustvox
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.14
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Gem for Trustvox API access.
147
+ test_files: []