Class: PlatformSdk::IdMapper::Client
- Inherits:
-
Object
- Object
- PlatformSdk::IdMapper::Client
- Defined in:
- lib/platform_sdk/id_mapper/client.rb
Overview
IdMapper::Client
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #create_pair(payload) ⇒ Object
- #domain_by_name(name) ⇒ Object
- #domains(**params) ⇒ Object
- #domains_by_key(key) ⇒ Object
-
#initialize(secret) ⇒ Client
constructor
A new instance of Client.
- #pairs(guid) ⇒ Object
Constructor Details
#initialize(secret) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 9 def initialize(secret) @token = secret[:token] @domain = secret[:domain] @token ||= PlatformSdk::IdMapper.token @domain ||= PlatformSdk::IdMapper.domain @conn = Faraday.new("https://#{@domain}") do |faraday| faraday.headers = headers faraday.adapter Faraday.default_adapter faraday.response :json, content_type: /\bjson$/ faraday.response :raise_error end end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
7 8 9 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 7 def conn @conn end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
7 8 9 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 7 def domain @domain end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 7 def token @token end |
Instance Method Details
#create_pair(payload) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 59 def create_pair(payload) raise StandardError, "Payload can not be empty." if payload.empty? path = "api/v1/pairs" post(path, payload) end |
#domain_by_name(name) ⇒ Object
72 73 74 75 76 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 72 def domain_by_name(name) path = "api/v1/domains/#{name}/" body = get(path) models::Domain.new(body) end |
#domains(**params) ⇒ Object
66 67 68 69 70 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 66 def domains(**params) path = 'api/v1/domains/' body = get(path, params) list_of_models(models::Domain, body) end |
#domains_by_key(key) ⇒ Object
78 79 80 81 82 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 78 def domains_by_key(key) path = "api/v1/domains?key=#{key}" body = get(path) list_of_models(models::Domain, body) end |
#pairs(guid) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/platform_sdk/id_mapper/client.rb', line 50 def pairs(guid) path = "api/v1/pairs/#{guid}" begin get(path) rescue Faraday::ResourceNotFound raise PlatformSdk::IdMapper::PairNotFoundError, msg = guid end end |