Class: ParcelApi::Client
- Inherits:
-
Object
- Object
- ParcelApi::Client
- Defined in:
- lib/parcel_api/client.rb
Instance Attribute Summary collapse
-
#address
Returns the value of attribute address.
-
#auth_address
Returns the value of attribute auth_address.
-
#client_id
Returns the value of attribute client_id.
-
#client_secret
Returns the value of attribute client_secret.
-
#password
Returns the value of attribute password.
-
#username
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #connection
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 |
# File 'lib/parcel_api/client.rb', line 15
def initialize
@client_id = client_id || ENV['CLIENT_ID']
@client_secret = client_secret || ENV['CLIENT_SECRET']
@username = username || ENV['USERNAME']
@password = password || ENV['PASSWORD']
@address = address || 'https://api.nzpost.co.nz'
@auth_address = auth_address || 'https://oauth.nzpost.co.nz/as/token.oauth2'
end
|
Instance Attribute Details
#address
Returns the value of attribute address.
4 5 6 |
# File 'lib/parcel_api/client.rb', line 4
def address
@address
end
|
#auth_address
Returns the value of attribute auth_address.
4 5 6 |
# File 'lib/parcel_api/client.rb', line 4
def auth_address
@auth_address
end
|
#client_id
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/parcel_api/client.rb', line 4
def client_id
@client_id
end
|
#client_secret
Returns the value of attribute client_secret.
4 5 6 |
# File 'lib/parcel_api/client.rb', line 4
def client_secret
@client_secret
end
|
#password
Returns the value of attribute password.
4 5 6 |
# File 'lib/parcel_api/client.rb', line 4
def password
@password
end
|
#username
Returns the value of attribute username.
4 5 6 |
# File 'lib/parcel_api/client.rb', line 4
def username
@username
end
|
Class Method Details
.connection
11 12 13 |
# File 'lib/parcel_api/client.rb', line 11
def self.connection
@connection ||= new.connection
end
|
Instance Method Details
#connection
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/parcel_api/client.rb', line 24
def connection
Faraday.new(url: @address) do |conn|
conn.authorization 'Bearer', token
conn.headers['client_id'] = @client_id
conn.request :json
conn.response :json, :content_type => /\bjson$/
conn.use FaradayMiddleware::RaiseHttpException
conn.adapter Faraday.default_adapter
end
end
|