-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PaymentMethod and Address modules
- Loading branch information
Showing
8 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'gogokit/utils' | ||
require 'gogokit/resource/address' | ||
|
||
module GogoKit | ||
class Client | ||
# {GogoKit::Client} methods for getting addresses for the authenticated user | ||
module Address | ||
include GogoKit::Utils | ||
|
||
# Retrieves all addresses for the authenticated user | ||
# | ||
# @see http://developer.viagogo.net/#useraddresses | ||
# @param [Hash] options Optional options | ||
# @return [GogoKit::PagedResource] All addresses for the authenticated | ||
# user | ||
def get_addresses(options = {}) | ||
root = get_root | ||
object_from_response(GogoKit::PagedResource, | ||
GogoKit::AddressesRepresenter, | ||
:get, | ||
"#{root.links['self'].href}/addresses", | ||
options) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'gogokit/utils' | ||
require 'gogokit/resource/payment_method' | ||
|
||
module GogoKit | ||
class Client | ||
# {GogoKit::Client} methods for getting payment methods for the | ||
# authenticated user | ||
module PaymentMethod | ||
include GogoKit::Utils | ||
|
||
# Retrieves all payment methods for the authenticated user | ||
# | ||
# @see http://developer.viagogo.net/#userpaymentmethods | ||
# @param [Hash] options Optional options | ||
# @return [GogoKit::PagedResource] All payment methods for the | ||
# authenticated user | ||
def get_payment_methods(options = {}) | ||
root = get_root | ||
object_from_response(GogoKit::PagedResource, | ||
GogoKit::PaymentMethodsRepresenter, | ||
:get, | ||
"#{root.links['self'].href}/paymentmethods", | ||
options) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'gogokit/resource' | ||
require 'gogokit/paged_resource' | ||
require 'gogokit/resource/country' | ||
|
||
module GogoKit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'gogokit/resource' | ||
require 'gogokit/paged_resource' | ||
require 'gogokit/resource/address' | ||
|
||
module GogoKit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'rspec' | ||
require 'spec_helper' | ||
|
||
describe GogoKit::Client::Address do | ||
let(:client) do | ||
GogoKit::Client.new(client_id: 'CK', client_secret: 'CS') | ||
end | ||
|
||
let(:root) do | ||
self_link = Roar::Hypermedia::Hyperlink.new(href: 'https://api.com/') | ||
root = GogoKit::Root.new | ||
root.links = { | ||
'self' => self_link | ||
} | ||
root | ||
end | ||
|
||
describe '#get_addresses' do | ||
it 'performs a get request' do | ||
allow(client).to receive(:get_root).and_return(root) | ||
stub_request(:any, /.*/).to_return(body: '{}') | ||
client.get_addresses | ||
expect(a_request(:get, /.*/)).to have_been_made | ||
end | ||
|
||
it 'performs a request built from the self link of the root resource' do | ||
self_link = Roar::Hypermedia::Hyperlink.new(href: 'https://apiroot.com') | ||
root = GogoKit::Root.new | ||
root.links = {'self' => self_link} | ||
expected_url = self_link.href + '/addresses' | ||
allow(client).to receive(:get_root).and_return(root) | ||
allow(client).to receive(:request).and_return(body: '{}', status: 200) | ||
client.get_addresses | ||
|
||
expect(client).to have_received(:request).with(anything, | ||
expected_url, | ||
anything) | ||
end | ||
|
||
it 'passes the given options in the request' do | ||
expected_options = {params: {foo: 5}, headers: {bar: '50'}} | ||
allow(client).to receive(:get_root).and_return(root) | ||
allow(client).to receive(:request).and_return(body: '{}', status: 200) | ||
client.get_addresses expected_options | ||
|
||
expect(client).to have_received(:request) do |_, _, options| | ||
expect(options).to eq(expected_options) | ||
end | ||
end | ||
|
||
it 'returns {GogoKit::PagedResource} with {GogoKit::Address}' \ | ||
':items created from the response' do | ||
allow(client).to receive(:get_root).and_return(root) | ||
stub_request(:any, /.*/).to_return(body: fixture('addresses.json')) | ||
addresses = client.get_addresses | ||
expect(addresses).to be_an_instance_of(GogoKit::PagedResource) | ||
expect(addresses.items[0]) | ||
.to be_an_instance_of(GogoKit::Address) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'rspec' | ||
require 'spec_helper' | ||
|
||
describe GogoKit::Client::PaymentMethod do | ||
let(:client) do | ||
GogoKit::Client.new(client_id: 'CK', client_secret: 'CS') | ||
end | ||
|
||
let(:root) do | ||
self_link = Roar::Hypermedia::Hyperlink.new(href: 'https://api.com/') | ||
root = GogoKit::Root.new | ||
root.links = { | ||
'self' => self_link | ||
} | ||
root | ||
end | ||
|
||
describe '#get_payment_methods' do | ||
it 'performs a get request' do | ||
allow(client).to receive(:get_root).and_return(root) | ||
stub_request(:any, /.*/).to_return(body: '{}') | ||
client.get_payment_methods | ||
expect(a_request(:get, /.*/)).to have_been_made | ||
end | ||
|
||
it 'performs a request built from the self link of the root resource' do | ||
self_link = Roar::Hypermedia::Hyperlink.new(href: 'https://apiroot.com') | ||
root = GogoKit::Root.new | ||
root.links = {'self' => self_link} | ||
expected_url = self_link.href + '/paymentmethods' | ||
allow(client).to receive(:get_root).and_return(root) | ||
allow(client).to receive(:request).and_return(body: '{}', status: 200) | ||
client.get_payment_methods | ||
|
||
expect(client).to have_received(:request).with(anything, | ||
expected_url, | ||
anything) | ||
end | ||
|
||
it 'passes the given options in the request' do | ||
expected_options = {params: {foo: 5}, headers: {bar: '50'}} | ||
allow(client).to receive(:get_root).and_return(root) | ||
allow(client).to receive(:request).and_return(body: '{}', status: 200) | ||
client.get_payment_methods expected_options | ||
|
||
expect(client).to have_received(:request) do |_, _, options| | ||
expect(options).to eq(expected_options) | ||
end | ||
end | ||
|
||
it 'returns {GogoKit::PagedResource} with {GogoKit::PaymentMethod}' \ | ||
':items created from the response' do | ||
allow(client).to receive(:get_root).and_return(root) | ||
stub_request(:any, /.*/).to_return(body: fixture('payment_methods.json')) | ||
payment_methods = client.get_payment_methods | ||
expect(payment_methods).to be_an_instance_of(GogoKit::PagedResource) | ||
expect(payment_methods.items[0]) | ||
.to be_an_instance_of(GogoKit::PaymentMethod) | ||
end | ||
end | ||
end |