Skip to content

Commit

Permalink
Added PaymentMethod and Address modules
Browse files Browse the repository at this point in the history
  • Loading branch information
akilburge committed Jul 3, 2015
1 parent 5ff7753 commit ce7aeac
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/gogokit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'gogokit/configuration'
require 'gogokit/connection'
require 'gogokit/error'
require 'gogokit/client/address'
require 'gogokit/client/category'
require 'gogokit/client/country'
require 'gogokit/client/currency'
Expand All @@ -11,6 +12,7 @@
require 'gogokit/client/listing'
require 'gogokit/client/metro_area'
require 'gogokit/client/oauth'
require 'gogokit/client/payment_method'
require 'gogokit/client/root'
require 'gogokit/client/search'
require 'gogokit/client/seller_listing'
Expand All @@ -25,6 +27,7 @@ module GogoKit
class Client
include GogoKit::Configuration
include GogoKit::Connection
include GogoKit::Client::Address
include GogoKit::Client::Category
include GogoKit::Client::Country
include GogoKit::Client::Currency
Expand All @@ -33,6 +36,7 @@ class Client
include GogoKit::Client::Listing
include GogoKit::Client::MetroArea
include GogoKit::Client::OAuth
include GogoKit::Client::PaymentMethod
include GogoKit::Client::Root
include GogoKit::Client::Search
include GogoKit::Client::SellerListing
Expand Down
26 changes: 26 additions & 0 deletions lib/gogokit/client/address.rb
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
27 changes: 27 additions & 0 deletions lib/gogokit/client/payment_method.rb
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
1 change: 1 addition & 0 deletions lib/gogokit/resource/address.rb
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
Expand Down
2 changes: 2 additions & 0 deletions lib/gogokit/resource/country.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'gogokit/resource'
require 'gogokit/paged_resource'
require 'gogokit/resource/country'

module GogoKit
# @see http://viagogo.github.io/developer.viagogo.net/#country
Expand Down
1 change: 1 addition & 0 deletions lib/gogokit/resource/payment_method.rb
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
Expand Down
61 changes: 61 additions & 0 deletions spec/gogokit/client/address_spec.rb
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
61 changes: 61 additions & 0 deletions spec/gogokit/client/payment_method_spec.rb
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

0 comments on commit ce7aeac

Please sign in to comment.