rotessa-rb 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/.rspec +3 -0
- data/.rubocop.yml +4 -0
- data/.standard.yml +3 -0
- data/.tool-versions +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +105 -0
- data/README.md +25 -0
- data/Rakefile +10 -0
- data/lib/rotessa/client.rb +113 -0
- data/lib/rotessa/rb.rb +1 -0
- data/lib/rotessa/version.rb +5 -0
- data/lib/rotessa.rb +14 -0
- data/rotessa.gemspec +36 -0
- data/sig/rotessa.rbs +4 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d217b93b89421a40ba97cd893108d6ca8e6eda3e1afd5653c55903ee8640b625
|
4
|
+
data.tar.gz: fb28bc40c9cc40da851c274a820ef753cbb66f6e065cff698b000699ee9fda35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 817cdcaa70b23b5e41f595052b109773cbaba8375114d6b0ed42329c3435b0da41d6584d40e377b7ca4c358d9d9ccf2093ccc4c3a51733105705cb2974eae86b
|
7
|
+
data.tar.gz: 64852448738a2a7d6506a873c592759020ed8bda132ea0c17470e2933d2c03ee0b8f8434dd5007e52712edae77c3ccb35f615f52d1edd9196f609d79db0f1692
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.standard.yml
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.1.2
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in rotessa.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
gem "rspec", "~> 3.0"
|
10
|
+
gem "standard", "~> 1.3"
|
11
|
+
gem "rubocop", "~> 1.20"
|
12
|
+
gem "ruby-lsp", "~> 0.3.8", group: :development
|
13
|
+
gem "dotenv"
|
14
|
+
gem "debug"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rotessa-rb (0.1.0)
|
5
|
+
activesupport (>= 6.0)
|
6
|
+
httparty (~> 0.21)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (7.0.4)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
ast (2.4.2)
|
17
|
+
concurrent-ruby (1.2.0)
|
18
|
+
debug (1.7.0)
|
19
|
+
irb (>= 1.5.0)
|
20
|
+
reline (>= 0.3.1)
|
21
|
+
diff-lcs (1.5.0)
|
22
|
+
dotenv (2.7.6)
|
23
|
+
httparty (0.21.0)
|
24
|
+
mini_mime (>= 1.0.0)
|
25
|
+
multi_xml (>= 0.5.2)
|
26
|
+
i18n (1.12.0)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
io-console (0.6.0)
|
29
|
+
irb (1.6.2)
|
30
|
+
reline (>= 0.3.0)
|
31
|
+
json (2.6.3)
|
32
|
+
language_server-protocol (3.17.0.2)
|
33
|
+
mini_mime (1.1.2)
|
34
|
+
minitest (5.17.0)
|
35
|
+
multi_xml (0.6.0)
|
36
|
+
parallel (1.22.1)
|
37
|
+
parser (3.1.3.0)
|
38
|
+
ast (~> 2.4.1)
|
39
|
+
prettier_print (1.2.0)
|
40
|
+
rainbow (3.1.1)
|
41
|
+
rake (13.0.6)
|
42
|
+
regexp_parser (2.6.1)
|
43
|
+
reline (0.3.2)
|
44
|
+
io-console (~> 0.5)
|
45
|
+
rexml (3.2.5)
|
46
|
+
rspec (3.12.0)
|
47
|
+
rspec-core (~> 3.12.0)
|
48
|
+
rspec-expectations (~> 3.12.0)
|
49
|
+
rspec-mocks (~> 3.12.0)
|
50
|
+
rspec-core (3.12.0)
|
51
|
+
rspec-support (~> 3.12.0)
|
52
|
+
rspec-expectations (3.12.1)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.12.0)
|
55
|
+
rspec-mocks (3.12.1)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.12.0)
|
58
|
+
rspec-support (3.12.0)
|
59
|
+
rubocop (1.39.0)
|
60
|
+
json (~> 2.3)
|
61
|
+
parallel (~> 1.10)
|
62
|
+
parser (>= 3.1.2.1)
|
63
|
+
rainbow (>= 2.2.2, < 4.0)
|
64
|
+
regexp_parser (>= 1.8, < 3.0)
|
65
|
+
rexml (>= 3.2.5, < 4.0)
|
66
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
67
|
+
ruby-progressbar (~> 1.7)
|
68
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
69
|
+
rubocop-ast (1.24.0)
|
70
|
+
parser (>= 3.1.1.0)
|
71
|
+
rubocop-performance (1.15.1)
|
72
|
+
rubocop (>= 1.7.0, < 2.0)
|
73
|
+
rubocop-ast (>= 0.4.0)
|
74
|
+
ruby-lsp (0.3.8)
|
75
|
+
language_server-protocol (~> 3.17.0)
|
76
|
+
sorbet-runtime
|
77
|
+
syntax_tree (>= 5.0.0, < 6)
|
78
|
+
ruby-progressbar (1.11.0)
|
79
|
+
sorbet-runtime (0.5.10626)
|
80
|
+
standard (1.19.1)
|
81
|
+
language_server-protocol (~> 3.17.0.2)
|
82
|
+
rubocop (= 1.39.0)
|
83
|
+
rubocop-performance (= 1.15.1)
|
84
|
+
syntax_tree (5.2.0)
|
85
|
+
prettier_print (>= 1.2.0)
|
86
|
+
tzinfo (2.0.5)
|
87
|
+
concurrent-ruby (~> 1.0)
|
88
|
+
unicode-display_width (2.3.0)
|
89
|
+
|
90
|
+
PLATFORMS
|
91
|
+
arm64-darwin-21
|
92
|
+
arm64-darwin-22
|
93
|
+
|
94
|
+
DEPENDENCIES
|
95
|
+
debug
|
96
|
+
dotenv
|
97
|
+
rake (~> 13.0)
|
98
|
+
rotessa-rb!
|
99
|
+
rspec (~> 3.0)
|
100
|
+
rubocop (~> 1.20)
|
101
|
+
ruby-lsp (~> 0.3.8)
|
102
|
+
standard (~> 1.3)
|
103
|
+
|
104
|
+
BUNDLED WITH
|
105
|
+
2.3.23
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Rotessa
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Install the gem and add to the application's Gemfile by executing:
|
6
|
+
|
7
|
+
$ bundle add rotessa-rb
|
8
|
+
|
9
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
10
|
+
|
11
|
+
$ gem install rotessa-rb
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
TODO: Write usage instructions here
|
16
|
+
|
17
|
+
## Development
|
18
|
+
|
19
|
+
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.
|
20
|
+
|
21
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cmer/rotessa.
|
data/Rakefile
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "debug"
|
3
|
+
|
4
|
+
class Rotessa::Client
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
attr_reader :environment, :api_key
|
8
|
+
|
9
|
+
PAGE_SIZE = 1000 # Rotessa's default page size
|
10
|
+
|
11
|
+
def initialize(api_key: nil, environment: nil)
|
12
|
+
api_key ||= ENV["ROTESSA_API_KEY"]
|
13
|
+
environment ||= ENV["ROTESSA_ENVIRONMENT"]&.to_sym || :production
|
14
|
+
|
15
|
+
raise "Invalid environment: #{environment}. Only :production and :sandbox are accepted." unless [:production, :sandbox].include?(environment)
|
16
|
+
raise "Invalid API key: #{api_key}. API key must be a string." unless api_key.to_s != ""
|
17
|
+
|
18
|
+
@api_key = api_key
|
19
|
+
@environment = environment
|
20
|
+
|
21
|
+
set_base_uri
|
22
|
+
end
|
23
|
+
|
24
|
+
def customers(**query)
|
25
|
+
options = base_options.clone
|
26
|
+
options[:query].merge!(query)
|
27
|
+
|
28
|
+
get_all_pages("/customers", options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def customer(id:, **query)
|
32
|
+
options = base_options.clone
|
33
|
+
options[:query].merge!(query)
|
34
|
+
|
35
|
+
unless id.is_a?(Integer) || id.to_i.to_s == id.to_s
|
36
|
+
options[:query][:custom_identifier] = id
|
37
|
+
id = "show_with_custom_identifier"
|
38
|
+
end
|
39
|
+
|
40
|
+
path = build_path("/customers", id)
|
41
|
+
|
42
|
+
self.class.get(path, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def transactions(**query)
|
46
|
+
options = base_options.clone
|
47
|
+
options[:query].merge!(query)
|
48
|
+
get_all_pages("/transaction_report", options)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def set_base_uri
|
54
|
+
case environment
|
55
|
+
when :production
|
56
|
+
self.class.base_uri "https://api.rotessa.com/v1"
|
57
|
+
when :sandbox
|
58
|
+
self.class.base_uri "https://sandbox-api.rotessa.com/v1"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_path(base_path, *args)
|
63
|
+
path = base_path
|
64
|
+
(args || []).each do |arg|
|
65
|
+
path += "/#{arg}"
|
66
|
+
end
|
67
|
+
path
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_all_pages(path, options)
|
71
|
+
results = []
|
72
|
+
response = nil
|
73
|
+
options = options.merge(page: 0)
|
74
|
+
|
75
|
+
while fetch_next_page?(response)
|
76
|
+
options[:page] += 1
|
77
|
+
response = self.class.get(path, options)
|
78
|
+
|
79
|
+
return [response, errors_for(response)] if has_error?(response)
|
80
|
+
|
81
|
+
results += Array.wrap(response.parsed_response)
|
82
|
+
end
|
83
|
+
|
84
|
+
[response, results]
|
85
|
+
end
|
86
|
+
|
87
|
+
def fetch_next_page?(results)
|
88
|
+
results.nil? || results.size == PAGE_SIZE
|
89
|
+
end
|
90
|
+
|
91
|
+
def base_options
|
92
|
+
{headers: headers, query: {}}
|
93
|
+
end
|
94
|
+
|
95
|
+
def headers
|
96
|
+
{
|
97
|
+
"Content-Type" => "application/json",
|
98
|
+
"Accept" => "application/json",
|
99
|
+
"Authorization" => "Token token=\"#{api_key}\"",
|
100
|
+
"Accept-Encoding" => "gzip,deflate,identity"
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def has_error?(response)
|
105
|
+
response.nil? || !response.success? || (response.parsed_response.is_a?(Hash) && response["errors"].present?)
|
106
|
+
end
|
107
|
+
|
108
|
+
def errors_for(response)
|
109
|
+
return nil unless response&.parsed_response&.is_a?(Hash)
|
110
|
+
|
111
|
+
response["errors"]
|
112
|
+
end
|
113
|
+
end
|
data/lib/rotessa/rb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "../rotessa"
|
data/lib/rotessa.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
|
+
require "active_support/core_ext/hash/keys"
|
5
|
+
require "active_support/core_ext/hash/indifferent_access"
|
6
|
+
require "active_support/core_ext/array/wrap"
|
7
|
+
|
8
|
+
require_relative "rotessa/version"
|
9
|
+
require_relative "rotessa/client"
|
10
|
+
|
11
|
+
module Rotessa
|
12
|
+
class Error < StandardError; end
|
13
|
+
# Your code goes here...
|
14
|
+
end
|
data/rotessa.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rotessa/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rotessa-rb"
|
7
|
+
spec.version = Rotessa::VERSION
|
8
|
+
spec.authors = ["Carl Mercier"]
|
9
|
+
spec.email = ["foss@carlmercier.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby client library for Rotessa's API"
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = "https://github.com/cmer/rotessa-rb"
|
14
|
+
spec.required_ruby_version = ">= 3.1.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/cmer/rotessa-rb"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
spec.add_dependency "httparty", "~> 0.21"
|
32
|
+
spec.add_dependency "activesupport", ">= 6.0"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, check out our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
data/sig/rotessa.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rotessa-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carl Mercier
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-25 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.21'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.21'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- foss@carlmercier.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- ".standard.yml"
|
51
|
+
- ".tool-versions"
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/rotessa.rb
|
57
|
+
- lib/rotessa/client.rb
|
58
|
+
- lib/rotessa/rb.rb
|
59
|
+
- lib/rotessa/version.rb
|
60
|
+
- rotessa.gemspec
|
61
|
+
- sig/rotessa.rbs
|
62
|
+
homepage: https://github.com/cmer/rotessa-rb
|
63
|
+
licenses: []
|
64
|
+
metadata:
|
65
|
+
homepage_uri: https://github.com/cmer/rotessa-rb
|
66
|
+
source_code_uri: https://github.com/cmer/rotessa-rb
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.0
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubygems_version: 3.3.7
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Ruby client library for Rotessa's API
|
86
|
+
test_files: []
|