nuvemshop 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +12 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.rubocop.yml +84 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +77 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nuvemshop.rb +39 -0
- data/lib/nuvemshop/extensions/credentiable.rb +11 -0
- data/lib/nuvemshop/extensions/mass_assignment.rb +11 -0
- data/lib/nuvemshop/orders.rb +32 -0
- data/lib/nuvemshop/request.rb +77 -0
- data/lib/nuvemshop/response.rb +52 -0
- data/lib/nuvemshop/version.rb +3 -0
- data/nuvemshop.gemspec +39 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f42327f74d6d6e4bb185dd88853629b2ef035ef7e4fd26b295ec234bbeb04012
|
4
|
+
data.tar.gz: 39aaefb3334b0fc951a87151e841580c66ef5691e641441e1861f8f534fd126c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 368209d80ce189ff9ee474379570fb8c6af0c99e0534c2683d3b0a13815d38c6c61042c3bdbedff529ae8d57102a22aa1211706bfce4be5fe6464dcbd94efc33
|
7
|
+
data.tar.gz: f06e3f5de4822ea751de805681aed5d4bfba9038210e4acbb597faac3c0687148cb599508a2d5e073d6f9f1cc58e3e5d7b6c0b1d464c3a7b3e5629086456bcca
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- "Rakefile"
|
8
|
+
SuggestExtensions: false
|
9
|
+
|
10
|
+
# Layout
|
11
|
+
Layout/LineLength:
|
12
|
+
AutoCorrect: true
|
13
|
+
Max: 120
|
14
|
+
Layout/SpaceAroundMethodCallOperator:
|
15
|
+
Enabled: false
|
16
|
+
Layout/IndentationConsistency:
|
17
|
+
Enabled: true
|
18
|
+
AutoCorrect: true
|
19
|
+
EnforcedStyle: indented_internal_methods
|
20
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
21
|
+
Enabled: true
|
22
|
+
AutoCorrect: true
|
23
|
+
|
24
|
+
# Lint
|
25
|
+
Lint/RaiseException:
|
26
|
+
Enabled: false
|
27
|
+
Lint/StructNewOverride:
|
28
|
+
Enabled: false
|
29
|
+
Lint/Debugger:
|
30
|
+
Enabled: true
|
31
|
+
Severity: error
|
32
|
+
|
33
|
+
# Metrics
|
34
|
+
Metrics/ClassLength:
|
35
|
+
Enabled: false
|
36
|
+
Metrics/AbcSize:
|
37
|
+
Enabled: false
|
38
|
+
Metrics/MethodLength:
|
39
|
+
Enabled: false
|
40
|
+
Metrics/BlockLength:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
# Style
|
44
|
+
Style/Documentation:
|
45
|
+
Enabled: false
|
46
|
+
Style/FrozenStringLiteralComment:
|
47
|
+
Enabled: false
|
48
|
+
Style/HashEachMethods:
|
49
|
+
Enabled: false
|
50
|
+
Style/HashTransformKeys:
|
51
|
+
Enabled: false
|
52
|
+
Style/HashTransformValues:
|
53
|
+
Enabled: false
|
54
|
+
Style/ExponentialNotation:
|
55
|
+
Enabled: true
|
56
|
+
Style/ClassAndModuleChildren:
|
57
|
+
AutoCorrect: true
|
58
|
+
EnforcedStyle: nested
|
59
|
+
Style/ClassMethods:
|
60
|
+
AutoCorrect: true
|
61
|
+
Style/StringLiterals:
|
62
|
+
EnforcedStyle: single_quotes
|
63
|
+
Style/TrivialAccessors:
|
64
|
+
ExactNameMatch: false
|
65
|
+
Enabled: false
|
66
|
+
Style/RedundantFreeze:
|
67
|
+
Enabled: true
|
68
|
+
AutoCorrect: true
|
69
|
+
Style/RedundantRegexpCharacterClass:
|
70
|
+
Enabled: true
|
71
|
+
AutoCorrect: true
|
72
|
+
Style/RedundantRegexpEscape:
|
73
|
+
Enabled: true
|
74
|
+
AutoCorrect: true
|
75
|
+
Style/RedundantReturn:
|
76
|
+
AllowMultipleReturnValues: true
|
77
|
+
AutoCorrect: true
|
78
|
+
Style/HashLikeCase:
|
79
|
+
MinBranchesCount: 4
|
80
|
+
Style/SingleArgumentDig:
|
81
|
+
Enabled: false
|
82
|
+
Style/MutableConstant:
|
83
|
+
Enabled: true
|
84
|
+
AutoCorrect: true
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at eng.alexandreh@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nuvemshop (0.1.0)
|
5
|
+
httparty (~> 0.18)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
httparty (0.18.1)
|
14
|
+
mime-types (~> 3.0)
|
15
|
+
multi_xml (>= 0.5.2)
|
16
|
+
method_source (1.0.0)
|
17
|
+
mime-types (3.3.1)
|
18
|
+
mime-types-data (~> 3.2015)
|
19
|
+
mime-types-data (3.2021.0225)
|
20
|
+
multi_xml (0.6.0)
|
21
|
+
parallel (1.20.1)
|
22
|
+
parser (3.0.1.0)
|
23
|
+
ast (~> 2.4.1)
|
24
|
+
pry (0.14.1)
|
25
|
+
coderay (~> 1.1)
|
26
|
+
method_source (~> 1.0)
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (13.0.3)
|
29
|
+
regexp_parser (2.1.1)
|
30
|
+
rexml (3.2.5)
|
31
|
+
rspec (3.10.0)
|
32
|
+
rspec-core (~> 3.10.0)
|
33
|
+
rspec-expectations (~> 3.10.0)
|
34
|
+
rspec-mocks (~> 3.10.0)
|
35
|
+
rspec-core (3.10.1)
|
36
|
+
rspec-support (~> 3.10.0)
|
37
|
+
rspec-expectations (3.10.1)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-mocks (3.10.2)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.10.0)
|
43
|
+
rspec-support (3.10.2)
|
44
|
+
rubocop (1.13.0)
|
45
|
+
parallel (~> 1.10)
|
46
|
+
parser (>= 3.0.0.0)
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
48
|
+
regexp_parser (>= 1.8, < 3.0)
|
49
|
+
rexml
|
50
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
51
|
+
ruby-progressbar (~> 1.7)
|
52
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
53
|
+
rubocop-ast (1.4.1)
|
54
|
+
parser (>= 2.7.1.5)
|
55
|
+
rubocop-performance (1.11.0)
|
56
|
+
rubocop (>= 1.7.0, < 2.0)
|
57
|
+
rubocop-ast (>= 0.4.0)
|
58
|
+
rubocop-rspec (2.2.0)
|
59
|
+
rubocop (~> 1.0)
|
60
|
+
rubocop-ast (>= 1.1.0)
|
61
|
+
ruby-progressbar (1.11.0)
|
62
|
+
unicode-display_width (2.0.0)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
nuvemshop!
|
69
|
+
pry
|
70
|
+
rake (~> 13.0)
|
71
|
+
rspec (~> 3.0)
|
72
|
+
rubocop (~> 1.12)
|
73
|
+
rubocop-performance (~> 1.11)
|
74
|
+
rubocop-rspec (~> 2.2)
|
75
|
+
|
76
|
+
BUNDLED WITH
|
77
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Alexandre Stapenhorst
|
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,44 @@
|
|
1
|
+
# NuvemshopRuby
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nuvemshop`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'nuvemshop'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install nuvemshop
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nuvemshop-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/nuvemshop_ruby/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the NuvemshopRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nuvemshop_ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task default: :spec
|
8
|
+
|
9
|
+
RuboCop::RakeTask.new do |task|
|
10
|
+
task.requires << 'rubocop-performance'
|
11
|
+
task.requires << 'rubocop-rspec'
|
12
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'nuvemshop'
|
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
data/lib/nuvemshop.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
require 'nuvemshop/extensions/credentiable'
|
5
|
+
require 'nuvemshop/extensions/mass_assignment'
|
6
|
+
|
7
|
+
require 'nuvemshop/version'
|
8
|
+
require 'nuvemshop/response'
|
9
|
+
require 'nuvemshop/request'
|
10
|
+
require 'nuvemshop/orders'
|
11
|
+
|
12
|
+
module Nuvemshop
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :client_id, :client_secret
|
17
|
+
attr_writer :api_version, :user_agent, :store_access_token, :store_user_id
|
18
|
+
|
19
|
+
def config
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
|
23
|
+
def api_version
|
24
|
+
@api_version ||= 'v1'
|
25
|
+
end
|
26
|
+
|
27
|
+
def user_agent
|
28
|
+
@user_agent ||= 'Nuvemshop Gem(https://github.com/alexandreh92/nuvemshop-ruby)'
|
29
|
+
end
|
30
|
+
|
31
|
+
def store_user_id
|
32
|
+
@store_user_id ||= nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def store_access_token
|
36
|
+
@store_access_token ||= nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Nuvemshop
|
2
|
+
module Extensions
|
3
|
+
module MassAssignment
|
4
|
+
def initialize(options = {})
|
5
|
+
before_initialize if respond_to?(:before_initialize, true)
|
6
|
+
options.each { |key, value| public_send("#{key}=", value) }
|
7
|
+
after_initialize if respond_to?(:after_initialize, true)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Nuvemshop
|
2
|
+
class Orders < Request
|
3
|
+
include Extensions::Credentiable
|
4
|
+
|
5
|
+
PATH = 'orders'.freeze
|
6
|
+
|
7
|
+
def self.all(opts = {})
|
8
|
+
new(access_token: opts[:access_token], user_id: opts[:user_id]).get(
|
9
|
+
action: PATH,
|
10
|
+
query: {
|
11
|
+
since_id: opts[:since_id],
|
12
|
+
status: opts[:status],
|
13
|
+
channels: opts[:channels],
|
14
|
+
payment_status: opts[:payment_status],
|
15
|
+
shipping_status: opts[:shipping_status],
|
16
|
+
created_at_min: opts[:created_at_min],
|
17
|
+
created_at_max: opts[:created_at_max],
|
18
|
+
updated_at_min: opts[:updated_at_min],
|
19
|
+
updated_at_max: opts[:updated_at_max],
|
20
|
+
total_min: opts[:total_min],
|
21
|
+
total_max: opts[:total_max],
|
22
|
+
customer_ids: opts[:customer_ids],
|
23
|
+
page: opts[:page],
|
24
|
+
per_page: opts[:per_page],
|
25
|
+
fields: opts[:fields],
|
26
|
+
q: opts[:q],
|
27
|
+
app_id: opts[:app_id]
|
28
|
+
}
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Nuvemshop
|
2
|
+
class Request
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
attr_accessor :response
|
8
|
+
attr_reader :access_token, :user_id, :options
|
9
|
+
|
10
|
+
BASE_URL = 'https://api.tiendanube.com/v1'.freeze
|
11
|
+
|
12
|
+
def initialize(*block)
|
13
|
+
@base_url = "#{BASE_URL}/#{set_store}"
|
14
|
+
@headers = set_headers
|
15
|
+
yield block if block_given?
|
16
|
+
@options = { headers: @headers }
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(opts = {})
|
20
|
+
perform_request(__method__, opts)
|
21
|
+
end
|
22
|
+
|
23
|
+
def post(opts = {})
|
24
|
+
perform_request(__method__, opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
def put(opts = {})
|
28
|
+
perform_request(__method__, opts)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete(opts = {})
|
32
|
+
perform_request(__method__, opts)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.respond_with(response); end
|
38
|
+
|
39
|
+
def perform_request(method, opts = {})
|
40
|
+
self.class.send(method.to_sym, path(opts[:action]), merge_options(opts))
|
41
|
+
end
|
42
|
+
|
43
|
+
def merge_options(opts = {})
|
44
|
+
@options.merge!(body: serialize_hash(opts[:body]), query: sanitize_hash(opts[:query]))
|
45
|
+
end
|
46
|
+
|
47
|
+
def serialize_hash(opts = {})
|
48
|
+
return unless opts
|
49
|
+
|
50
|
+
sanitize_hash(opts).to_json
|
51
|
+
end
|
52
|
+
|
53
|
+
def sanitize_hash(opts = {})
|
54
|
+
opts.keep_if { |_, v| v }
|
55
|
+
end
|
56
|
+
|
57
|
+
def path(action)
|
58
|
+
"#{@base_url}/#{action}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_headers
|
62
|
+
{
|
63
|
+
"Content-Type": 'application/json',
|
64
|
+
'Authentication': "bearer #{set_access_token}",
|
65
|
+
'User-Agent': Nuvemshop.user_agent
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_access_token
|
70
|
+
access_token || Nuvemshop.store_access_token
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_store
|
74
|
+
user_id || Nuvemshop.store_user_id
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Nuvemshop
|
2
|
+
class Response < Object
|
3
|
+
attr_reader :response, :body, :code, :headers, :parsed_response
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
@code = response.code
|
8
|
+
@body = response.body
|
9
|
+
@headers = response.headers
|
10
|
+
@parsed_response = response.parsed_response
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
if !response.nil? && !response.body.nil? && response.body.respond_to?(:to_s)
|
15
|
+
response.body.to_s
|
16
|
+
else
|
17
|
+
inspect
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
inspect_id = ::Kernel.format '%x', (object_id * 2)
|
23
|
+
%(#<#{self.class}:0x#{inspect_id} code, @response=#{response.inspect}, @headers=#{headers.inspect}>)
|
24
|
+
end
|
25
|
+
|
26
|
+
def pretty_print(pp)
|
27
|
+
if !parsed_response.nil? && parsed_response.respond_to?(:pretty_print)
|
28
|
+
parsed_response.pretty_print(pp)
|
29
|
+
else
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def respond_to_missing?(name, *args)
|
35
|
+
return true if super
|
36
|
+
|
37
|
+
parsed_response.respond_to?(name) || response.respond_to?(name)
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def method_missing(name, *args, &block)
|
43
|
+
if parsed_response.respond_to?(name)
|
44
|
+
parsed_response.send(name, *args, &block)
|
45
|
+
elsif response.respond_to?(name)
|
46
|
+
response.send(name, *args, &block)
|
47
|
+
else
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/nuvemshop.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'lib/nuvemshop/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'nuvemshop'
|
5
|
+
spec.version = Nuvemshop::VERSION
|
6
|
+
spec.authors = ['Alexandre Stapenhorst']
|
7
|
+
spec.email = ['eng.alexandreh@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = 'Write a short summary, because RubyGems requires one.'
|
10
|
+
spec.description = 'Write a longer description or delete this line.'
|
11
|
+
spec.homepage = 'https://github.com/alexandreh92/nuvemshop-ruby'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
14
|
+
|
15
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/alexandreh92/nuvemshop-ruby'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/alexandreh92/nuvemshop-ruby/CHANGELOG.md'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
# Dependencies
|
31
|
+
# Runtime
|
32
|
+
spec.add_dependency 'httparty', '~> 0.18'
|
33
|
+
|
34
|
+
# Development
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 1.12'
|
36
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.11'
|
37
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.2'
|
38
|
+
spec.add_development_dependency 'pry'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nuvemshop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandre Stapenhorst
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-performance
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
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
|
+
description: Write a longer description or delete this line.
|
84
|
+
email:
|
85
|
+
- eng.alexandreh@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".editorconfig"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- lib/nuvemshop.rb
|
104
|
+
- lib/nuvemshop/extensions/credentiable.rb
|
105
|
+
- lib/nuvemshop/extensions/mass_assignment.rb
|
106
|
+
- lib/nuvemshop/orders.rb
|
107
|
+
- lib/nuvemshop/request.rb
|
108
|
+
- lib/nuvemshop/response.rb
|
109
|
+
- lib/nuvemshop/version.rb
|
110
|
+
- nuvemshop.gemspec
|
111
|
+
homepage: https://github.com/alexandreh92/nuvemshop-ruby
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata:
|
115
|
+
allowed_push_host: https://rubygems.org
|
116
|
+
homepage_uri: https://github.com/alexandreh92/nuvemshop-ruby
|
117
|
+
source_code_uri: https://github.com/alexandreh92/nuvemshop-ruby
|
118
|
+
changelog_uri: https://github.com/alexandreh92/nuvemshop-ruby/CHANGELOG.md
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 2.3.0
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubygems_version: 3.0.8
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Write a short summary, because RubyGems requires one.
|
138
|
+
test_files: []
|