Class: Runa::Client
- Inherits:
-
Object
- Object
- Runa::Client
- Defined in:
- lib/runa/client.rb
Instance Attribute Summary collapse
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_path ⇒ Object
Returns the value of attribute api_path.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
supported: basic-http-auth - see: playground.runa.io.
- #order(options) ⇒ Object
- #product(id = nil) ⇒ Object
-
#products ⇒ Object
global methods.
- #remote_code(url) ⇒ Object
- #request(method, path, payload = {}, key) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
supported: basic-http-auth - see: playground.runa.io
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/runa/client.rb', line 18 def initialize( = {}) @api_host = [:api_host] || 'https://playground.runa.io' @api_path = [:api_path] || '/v2' @api_key = [:api_key].to_s @connection = Faraday.new(url: @api_host) do |c| c.adapter Faraday.default_adapter unless [:proxy].nil? c.[:proxy] = { uri: URI([:proxy]) } end end end |
Instance Attribute Details
#api_host ⇒ Object
Returns the value of attribute api_host.
14 15 16 |
# File 'lib/runa/client.rb', line 14 def api_host @api_host end |
#api_key ⇒ Object
Returns the value of attribute api_key.
14 15 16 |
# File 'lib/runa/client.rb', line 14 def api_key @api_key end |
#api_path ⇒ Object
Returns the value of attribute api_path.
14 15 16 |
# File 'lib/runa/client.rb', line 14 def api_path @api_path end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
14 15 16 |
# File 'lib/runa/client.rb', line 14 def api_secret @api_secret end |
#connection ⇒ Object
Returns the value of attribute connection.
14 15 16 |
# File 'lib/runa/client.rb', line 14 def connection @connection end |
Instance Method Details
#order(options) ⇒ Object
64 65 66 67 |
# File 'lib/runa/client.rb', line 64 def order() order = Runa::Order.new() order.post(self) end |
#product(id = nil) ⇒ Object
59 60 61 62 |
# File 'lib/runa/client.rb', line 59 def product(id = nil) products = Runa::Product.new(product_code: id) products.get(self) end |
#products ⇒ Object
global methods
54 55 56 57 |
# File 'lib/runa/client.rb', line 54 def products products = Runa::Products.new products.get(self) end |
#remote_code(url) ⇒ Object
69 70 71 72 |
# File 'lib/runa/client.rb', line 69 def remote_code(url) code = Runa::RemoteCode.new(url: url) code.get(self) end |
#request(method, path, payload = {}, key) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/runa/client.rb', line 33 def request(method, path, payload = {}, key) @connection.send(method) do |req| req.url [@api_path, path].join req.headers['Content-Type'] = 'application/json'.freeze req.headers['X-Api-Key'] = @api_key req.headers['X-Api-Version'] = '2024-02-05'.freeze req.headers['X-Execution-Mode'] = 'sync'.freeze if method.eql? :post raise StandardError('Required idempotency key missing') if key.nil? || key.strip == '' req.headers['X-Idempotency-Key'] = key end req.body = payload.to_json if method.to_sym.eql?(:post) req.params = payload if method.to_sym.eql?(:get) end end |