runa-ruby-client 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.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/runa/client.rb +74 -0
- data/lib/runa/models/initializable.rb +10 -0
- data/lib/runa/models/order.rb +78 -0
- data/lib/runa/models/product.rb +37 -0
- data/lib/runa/models/products.rb +34 -0
- data/lib/runa/models/remote_code.rb +33 -0
- data/lib/runa/models/response.rb +41 -0
- data/lib/runa/version.rb +6 -0
- data/lib/runa.rb +14 -0
- data/runa-ruby-client.gemspec +34 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ac2b547a1b85e1635e6c09b007f2f38cb8495434a61320940871cce787d1c1e
|
4
|
+
data.tar.gz: 7ab3dd25f6e4fe0d6200660534c82a1567721bf3e8f962c7f0660869e3c10afb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c932a61e08eca8e1c6fbc051698aca60e88d0812e5e4b9f241eaeb02655746a95472c896620b474e80e6e193c2469c8567017a521ba766379a92f7527c00ada0
|
7
|
+
data.tar.gz: 34a8677a24af1c0d4adaab3b5c8ad9214b2a25ac73d03fa5c0ee8f380fd2e8f3b5ce4caaa6601dfe24cf844766d670fa5a916f7b354bfc8ecb4f866c2f514e1f
|
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
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
|
13
|
+
|
14
|
+
# debugger
|
15
|
+
.byebug_history
|
16
|
+
|
17
|
+
# idea/rubymine
|
18
|
+
*.iml
|
19
|
+
|
20
|
+
# rvm
|
21
|
+
.ruby-gemset
|
22
|
+
.ruby-version
|
23
|
+
|
24
|
+
# vars for testing
|
25
|
+
.env
|
26
|
+
|
27
|
+
# gems
|
28
|
+
runa-ruby-client-*.gem
|
data/.rspec
ADDED
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 klaas.endrikat@googlemail.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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 ThanksBox Ltd
|
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,118 @@
|
|
1
|
+
# Runa Ruby Client
|
2
|
+
|
3
|
+
A simple client for [Runa.io][runa] B2B Synchronous API (Document Version 1.7).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'runa-ruby-client'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
```bash
|
15
|
+
$ bundle
|
16
|
+
```
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
```bash
|
20
|
+
$ gem install runa-ruby-client
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Simple example for ordering a Digital Card
|
26
|
+
```ruby
|
27
|
+
# a simple client
|
28
|
+
client = Runa::Client.new(
|
29
|
+
:api_host => 'https://playground.runa.io',
|
30
|
+
:api_path => '/api/b2b-sync/v1',
|
31
|
+
:api_key => ENV['AUTH_NAME'],
|
32
|
+
:api_secret => ENV['AUTH_PASS'],
|
33
|
+
:proxy => ENV['PROXY']
|
34
|
+
)
|
35
|
+
|
36
|
+
# with all available products
|
37
|
+
get_products = client.products
|
38
|
+
|
39
|
+
if get_products.is_successful?
|
40
|
+
# it provides a list of all vouchers
|
41
|
+
vouchers = products.all
|
42
|
+
else
|
43
|
+
# get_products.status => 403
|
44
|
+
# get_products.error_details => "Forbidden"
|
45
|
+
end
|
46
|
+
|
47
|
+
# or just a single one
|
48
|
+
product = client.products('PROD-ID')
|
49
|
+
|
50
|
+
# and data
|
51
|
+
product.description
|
52
|
+
product.redeem_instructions_html
|
53
|
+
product.e_code_usage_type
|
54
|
+
# ... etc
|
55
|
+
|
56
|
+
# post a simple order
|
57
|
+
order = client.order(
|
58
|
+
:product_code => product.code,
|
59
|
+
:currency_code => 'USD',
|
60
|
+
:amount => '42.00',
|
61
|
+
:delivery_method => 'direct', # default
|
62
|
+
:delivery_format => 'raw', # default
|
63
|
+
:external_ref => '123' # optional
|
64
|
+
)
|
65
|
+
|
66
|
+
# which returns
|
67
|
+
if order.is_successful?
|
68
|
+
|
69
|
+
# some nice data
|
70
|
+
order.code
|
71
|
+
order.order_id
|
72
|
+
order.pin
|
73
|
+
order.barcode_format
|
74
|
+
order.barcode_string
|
75
|
+
order.expiry_date
|
76
|
+
order.delivery_url
|
77
|
+
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
## Development
|
82
|
+
|
83
|
+
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.
|
84
|
+
|
85
|
+
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).
|
86
|
+
|
87
|
+
### Testing
|
88
|
+
|
89
|
+
Run it!
|
90
|
+
```bash
|
91
|
+
rspec
|
92
|
+
```
|
93
|
+
|
94
|
+
It will load all tapes found in `spec/tapes`, we are using [VCR][vcr].
|
95
|
+
|
96
|
+
To remaster all recordings, you will need a playground account.
|
97
|
+
Add an `.env` file to your root:
|
98
|
+
|
99
|
+
```bash
|
100
|
+
# .env
|
101
|
+
AUTH_NAME='playground_username'
|
102
|
+
AUTH_PASS='playground_password'
|
103
|
+
PROXY='proxy_uri'
|
104
|
+
```
|
105
|
+
|
106
|
+
Start the VCR with `rspec` - this should add all Tapes to `spec/tapes`.
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mo-work/runa-ruby-client. 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.
|
111
|
+
|
112
|
+
|
113
|
+
## License
|
114
|
+
|
115
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
116
|
+
|
117
|
+
[runa]: http://Runa.io
|
118
|
+
[vcr]: https://github.com/vcr/vcr
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'runa'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/runa/client.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
require_relative 'models/response'
|
7
|
+
require_relative 'models/product'
|
8
|
+
require_relative 'models/products'
|
9
|
+
require_relative 'models/order'
|
10
|
+
require_relative 'models/remote_code'
|
11
|
+
|
12
|
+
module Runa
|
13
|
+
class Client
|
14
|
+
attr_accessor :api_host, :api_path, :api_key, :api_secret, :connection
|
15
|
+
|
16
|
+
# supported: basic-http-auth - see: https://playground.runa.io
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
@api_host = options[:api_host] || 'https://playground.runa.io'
|
20
|
+
@api_path = options[:api_path] || '/v2'
|
21
|
+
@api_key = options[:api_key].to_s
|
22
|
+
|
23
|
+
@connection = Faraday.new(url: @api_host) do |c|
|
24
|
+
c.adapter Faraday.default_adapter
|
25
|
+
unless options[:proxy].nil?
|
26
|
+
c.options[:proxy] = {
|
27
|
+
uri: URI(options[:proxy])
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def request(method, path, payload = {}, key)
|
34
|
+
@connection.send(method) do |req|
|
35
|
+
req.url [@api_path, path].join
|
36
|
+
req.headers['Content-Type'] = 'application/json'.freeze
|
37
|
+
req.headers['X-Api-Key'] = @api_key
|
38
|
+
req.headers['X-Api-Version'] = '2024-02-05'.freeze
|
39
|
+
req.headers['X-Execution-Mode'] = 'sync'.freeze
|
40
|
+
if method.eql? :post
|
41
|
+
raise StandardError('Required idempotency key missing') if key.nil? || key.strip == ''
|
42
|
+
req.headers['X-Idempotency-Key'] = key
|
43
|
+
end
|
44
|
+
req.body = payload.to_json if method.to_sym.eql?(:post)
|
45
|
+
req.params = payload if method.to_sym.eql?(:get)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# TODO: shared context/connection for all calls
|
50
|
+
# keep client => https://github.com/lostisland/faraday#basic-use
|
51
|
+
|
52
|
+
# global methods
|
53
|
+
|
54
|
+
def products
|
55
|
+
products = Runa::Products.new
|
56
|
+
products.get(self)
|
57
|
+
end
|
58
|
+
|
59
|
+
def product(id = nil)
|
60
|
+
products = Runa::Product.new(product_code: id)
|
61
|
+
products.get(self)
|
62
|
+
end
|
63
|
+
|
64
|
+
def order(options)
|
65
|
+
order = Runa::Order.new(options)
|
66
|
+
order.post(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
def remote_code(url)
|
70
|
+
code = Runa::RemoteCode.new(url: url)
|
71
|
+
code.get(self)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Runa::Order < Runa::Response
|
4
|
+
PATH = '/order'
|
5
|
+
|
6
|
+
DELIVERY_METHODS = { direct: 'direct', email: 'email' }.freeze
|
7
|
+
DELIVERY_FORMATS = { code: 'raw', url: 'url-instant' }.freeze
|
8
|
+
|
9
|
+
# request/payload
|
10
|
+
attr_accessor :payment_type, :currency, :face_value, :distribution_type, :product_code, :external_ref
|
11
|
+
|
12
|
+
# response/success
|
13
|
+
attr_accessor :code, :order_id, :status, :created_at, :payment_method, :currency, :total_price,
|
14
|
+
:total_discount, :items, :redemption_url, :order_id
|
15
|
+
|
16
|
+
def initialize(params = {})
|
17
|
+
super(params)
|
18
|
+
# default/fallback: 'direct'/'raw'
|
19
|
+
@delivery_method = params[:delivery_method] || DELIVERY_METHODS[:direct]
|
20
|
+
@delivery_format = params[:delivery_format] || DELIVERY_FORMATS[:code]
|
21
|
+
end
|
22
|
+
|
23
|
+
def payload
|
24
|
+
{
|
25
|
+
payment_method: {
|
26
|
+
type: @payment_type,
|
27
|
+
currency: @currency
|
28
|
+
},
|
29
|
+
items: [
|
30
|
+
{
|
31
|
+
face_value: @face_value,
|
32
|
+
distribution_method: {
|
33
|
+
type: @distribution_type
|
34
|
+
},
|
35
|
+
products: {
|
36
|
+
type: "SINGLE",
|
37
|
+
value: @product_code
|
38
|
+
}
|
39
|
+
}
|
40
|
+
],
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
# Create a new order
|
45
|
+
# POST /v2/order
|
46
|
+
def post(ctx)
|
47
|
+
response = ctx.request(:post, PATH, payload, @external_ref)
|
48
|
+
parse(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse(response)
|
52
|
+
super(response)
|
53
|
+
|
54
|
+
if @payload['status'].eql?(STATUS[:failed])
|
55
|
+
@status = @payload['status']
|
56
|
+
unless @payload['type'].blank?
|
57
|
+
@type = @payload['type']
|
58
|
+
end
|
59
|
+
unless @payload['message'].blank?
|
60
|
+
@message = @payload['message']
|
61
|
+
end
|
62
|
+
unless @payload['help'].blank?
|
63
|
+
@help = @payload['help']
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# set valid data
|
68
|
+
if @payload['status'] && @payload['status'].eql?(STATUS[:completed])
|
69
|
+
@status = @payload['status']
|
70
|
+
@total_price = @payload['total_price']
|
71
|
+
@items = @payload['items']
|
72
|
+
end
|
73
|
+
|
74
|
+
@order_id = @payload['id']
|
75
|
+
|
76
|
+
self
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Runa::Product < Runa::Response
|
4
|
+
PATH = '/product'
|
5
|
+
|
6
|
+
# request/payload
|
7
|
+
attr_accessor :product_code
|
8
|
+
|
9
|
+
# response/success
|
10
|
+
attr_accessor :code, :name, :description, :currency, :availability,
|
11
|
+
:countries_redeemable_in,
|
12
|
+
:categories,
|
13
|
+
:state,
|
14
|
+
:gift_card,
|
15
|
+
:subscription
|
16
|
+
|
17
|
+
def initialize(params = {})
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def path
|
22
|
+
[PATH, @product_code.to_s].join('/')
|
23
|
+
end
|
24
|
+
|
25
|
+
# Product Details List
|
26
|
+
# GET /v2/product/ID
|
27
|
+
def get(ctx)
|
28
|
+
response = ctx.request(:get, path, {}, '')
|
29
|
+
parse(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse(response)
|
33
|
+
super(response)
|
34
|
+
|
35
|
+
Runa::Product.new(@payload)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Runa::Products < Runa::Response
|
4
|
+
PATH = '/product'
|
5
|
+
|
6
|
+
attr_accessor :all
|
7
|
+
|
8
|
+
# Product Details List
|
9
|
+
# GET /v2/product
|
10
|
+
def get(ctx)
|
11
|
+
response = ctx.request(:get, PATH, {}, '')
|
12
|
+
parse(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Find all products by fieldname.
|
16
|
+
def find(name, value)
|
17
|
+
Runa::Products.new(all: all.select! { |p| p.send(name).eql?(value) })
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse(response)
|
21
|
+
super(response)
|
22
|
+
|
23
|
+
if is_successful?
|
24
|
+
# TODO: separate?
|
25
|
+
if @payload['catalog']
|
26
|
+
@all = @payload['catalog'].map { |p| Runa::Product.new(p) }
|
27
|
+
end
|
28
|
+
else
|
29
|
+
@all = []
|
30
|
+
end
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Runa
|
8
|
+
class RemoteCode < Response
|
9
|
+
attr_accessor :url
|
10
|
+
|
11
|
+
# response/success
|
12
|
+
attr_accessor :amount, :barcode_format, :barcode_string, :code, :expiry_date,
|
13
|
+
:pin, :type
|
14
|
+
|
15
|
+
def get(ctx)
|
16
|
+
conn = Faraday.new(url: url) do |c|
|
17
|
+
c.adapter :net_http
|
18
|
+
c.use FaradayMiddleware::FollowRedirects, limit: 5
|
19
|
+
end
|
20
|
+
parse(conn.get("#{url}?format=json") { |r| r.headers['Accept'] = 'application/json' })
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse(response)
|
24
|
+
super
|
25
|
+
|
26
|
+
if is_successful?
|
27
|
+
self.class.new(@payload['e_code'])
|
28
|
+
else
|
29
|
+
self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'initializable'
|
4
|
+
|
5
|
+
class Runa::Response
|
6
|
+
include Initializable
|
7
|
+
|
8
|
+
STATUS = { completed: 'COMPLETED', success: 'SUCCESS', processing: 'PROCESSING', failed: 'FAILED', error: 'ERROR' }.freeze
|
9
|
+
|
10
|
+
# Field Name Contents
|
11
|
+
#
|
12
|
+
# status - The status of the transaction. Usually “SUCCESS” or “ERROR”
|
13
|
+
# type - An error code or type.
|
14
|
+
# message - A human readable summary of the error.
|
15
|
+
# help - Additional information that pertains to the error. [optional]
|
16
|
+
|
17
|
+
# global shared body
|
18
|
+
attr_accessor :payload, :status, :error_code, :error_string, :error_details
|
19
|
+
|
20
|
+
def is_successful?
|
21
|
+
@status&.eql?(STATUS[:completed]) || @status&.eql?(STATUS[:success])
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse(response = {})
|
25
|
+
# TODO: JSON responses, when requested?
|
26
|
+
# let's fix that with a simpel catch all
|
27
|
+
if response.success? && response['content-type'].eql?('application/json')
|
28
|
+
@payload = JSON.parse(response.body)
|
29
|
+
@status = STATUS[:completed]
|
30
|
+
@error_code = @payload['type']
|
31
|
+
@error_string = @payload['message']
|
32
|
+
@error_details = @payload['help']
|
33
|
+
else
|
34
|
+
@payload = JSON.parse(response.body) unless !response['content-type'].eql?('application/json')
|
35
|
+
@status = STATUS[:failed]
|
36
|
+
@error_code = response.status
|
37
|
+
@error_string = response.reason_phrase
|
38
|
+
@error_details = response.reason_phrase
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/runa/version.rb
ADDED
data/lib/runa.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'runa/version'
|
4
|
+
require 'runa/client'
|
5
|
+
|
6
|
+
require 'runa/models/initializable'
|
7
|
+
require 'runa/models/response'
|
8
|
+
require 'runa/models/product'
|
9
|
+
require 'runa/models/products'
|
10
|
+
require 'runa/models/order'
|
11
|
+
require 'runa/models/stock'
|
12
|
+
|
13
|
+
module Runa
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'runa/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'runa-ruby-client'
|
9
|
+
spec.version = Runa::VERSION
|
10
|
+
spec.authors = ['Luke Oglesby']
|
11
|
+
spec.email = ['luke.oglesby@mo.work']
|
12
|
+
|
13
|
+
spec.summary = 'A simple Ruby client for the Runa Connect API'
|
14
|
+
spec.homepage = 'https://github.com/mo-work/runa-ruby-client'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.4.0'
|
22
|
+
|
23
|
+
spec.add_dependency 'faraday', '~> 1.0', '>= 1.0.0'
|
24
|
+
spec.add_dependency 'faraday_middleware', '~> 1.2'
|
25
|
+
spec.add_dependency 'json', '~> 2.3', '>= 2.3.0'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2.3.12'
|
28
|
+
spec.add_development_dependency 'byebug', '~> 11'
|
29
|
+
spec.add_development_dependency 'dotenv', '~> 2.2', '>= 2.2.0'
|
30
|
+
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
|
33
|
+
spec.add_development_dependency 'webmock', '~> 3.5', '>= 3.5.0'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: runa-ruby-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luke Oglesby
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-06 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: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday_middleware
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.2'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: json
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.3'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.3.0
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.3'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.3.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: bundler
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.3.12
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.3.12
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: byebug
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '11'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '11'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: dotenv
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.2'
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 2.2.0
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.2'
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 2.2.0
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: rake
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '12.3'
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 12.3.3
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '12.3'
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 12.3.3
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: rspec
|
137
|
+
requirement: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - "~>"
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '3.0'
|
142
|
+
type: :development
|
143
|
+
prerelease: false
|
144
|
+
version_requirements: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - "~>"
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '3.0'
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: vcr
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '3.0'
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 3.0.3
|
159
|
+
type: :development
|
160
|
+
prerelease: false
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '3.0'
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 3.0.3
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: webmock
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - "~>"
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '3.5'
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: 3.5.0
|
179
|
+
type: :development
|
180
|
+
prerelease: false
|
181
|
+
version_requirements: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - "~>"
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '3.5'
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 3.5.0
|
189
|
+
description:
|
190
|
+
email:
|
191
|
+
- luke.oglesby@mo.work
|
192
|
+
executables:
|
193
|
+
- console
|
194
|
+
- setup
|
195
|
+
extensions: []
|
196
|
+
extra_rdoc_files: []
|
197
|
+
files:
|
198
|
+
- ".gitignore"
|
199
|
+
- ".rspec"
|
200
|
+
- ".travis.yml"
|
201
|
+
- CODE_OF_CONDUCT.md
|
202
|
+
- Gemfile
|
203
|
+
- LICENSE.txt
|
204
|
+
- README.md
|
205
|
+
- Rakefile
|
206
|
+
- bin/console
|
207
|
+
- bin/setup
|
208
|
+
- lib/runa.rb
|
209
|
+
- lib/runa/client.rb
|
210
|
+
- lib/runa/models/initializable.rb
|
211
|
+
- lib/runa/models/order.rb
|
212
|
+
- lib/runa/models/product.rb
|
213
|
+
- lib/runa/models/products.rb
|
214
|
+
- lib/runa/models/remote_code.rb
|
215
|
+
- lib/runa/models/response.rb
|
216
|
+
- lib/runa/version.rb
|
217
|
+
- runa-ruby-client.gemspec
|
218
|
+
homepage: https://github.com/mo-work/runa-ruby-client
|
219
|
+
licenses:
|
220
|
+
- MIT
|
221
|
+
metadata: {}
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
require_paths:
|
225
|
+
- lib
|
226
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: 2.4.0
|
231
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - ">="
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '0'
|
236
|
+
requirements: []
|
237
|
+
rubygems_version: 3.1.6
|
238
|
+
signing_key:
|
239
|
+
specification_version: 4
|
240
|
+
summary: A simple Ruby client for the Runa Connect API
|
241
|
+
test_files: []
|