Class: Merchant
- Inherits:
-
Object
- Object
- Merchant
- Defined in:
- lib/capital_one/merchant.rb
Class Method Summary collapse
- .apiKey ⇒ Object
-
.createMerchant(merchant) ⇒ Object
Creates a new Merchant = Parameters: MerchantHash MerchantHash format is as follows: { “name”: “string”, “address”: { “street_number”: “string”, “street_name”: “string”, “city”: “string”, “state”: “string”, “zip”: “string”, }, “geocode”: { “lat”: 0, “lng”: 0, } } Returns http response code.
-
.getAll ⇒ Object
Returns all Merchants as an array of hashes.
-
.getAllByLocation(lat, lng, rad) ⇒ Object
Returns all Merchants within a given location range = Parameters: Latitude, Longitude, Radius Accepts lat, lng, and rad as floats Returns an array of hashes.
-
.getOne(merchId) ⇒ Object
Returns a single merchant for a given ID = Parameters: MerchantId Returns a hash.
-
.updateMerchant(merchId, merchant) ⇒ Object
Updates an existing Merchant = Parameters: MerchantId, MerchantHash MerchantHash format is as follows: { “name”: “string”, “address”: { “street_number”: “string”, “street_name”: “string”, “city”: “string”, “state”: “string”, “zip”: “string”, }, “geocode”: { “lat”: 0, “lng”: 0, } } Returns http response code.
- .url ⇒ Object
- .urlWithEntity ⇒ Object
Class Method Details
.apiKey ⇒ Object
11 12 13 |
# File 'lib/capital_one/merchant.rb', line 11 def self.apiKey return Config.apiKey end |
.createMerchant(merchant) ⇒ Object
Creates a new Merchant
Parameters: MerchantHash
MerchantHash format is as follows: { “name”: “string”, “address”: { “street_number”: “string”, “street_name”: “string”, “city”: “string”, “state”: “string”, “zip”: “string”, }, “geocode”: { “lat”: 0, “lng”: 0, } } Returns http response code
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/capital_one/merchant.rb', line 107 def self.createMerchant(merchant) merchantToCreate = merchant.to_json url = "#{self.urlWithEntity}/?key=#{self.apiKey}" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'}) request.body = merchantToCreate resp = http.request(request) data = JSON.parse(resp.body) end |
.getAll ⇒ Object
Returns all Merchants as an array of hashes
19 20 21 22 23 24 |
# File 'lib/capital_one/merchant.rb', line 19 def self.getAll url = "#{self.urlWithEntity}?key=#{self.apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(resp.body) return data end |
.getAllByLocation(lat, lng, rad) ⇒ Object
Returns all Merchants within a given location range
Parameters: Latitude, Longitude, Radius
Accepts lat, lng, and rad as floats Returns an array of hashes
32 33 34 35 36 37 |
# File 'lib/capital_one/merchant.rb', line 32 def self.getAllByLocation(lat, lng, rad) url = "#{self.urlWithEntity}?lat=#{lat}&lng=#{lng}&rad=#{rad}&key=#{self.apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(resp.body) return data end |
.getOne(merchId) ⇒ Object
Returns a single merchant for a given ID
Parameters: MerchantId
Returns a hash
44 45 46 47 48 49 |
# File 'lib/capital_one/merchant.rb', line 44 def self.getOne(merchId) url = "#{self.urlWithEntity}/#{merchId}?key=#{self.apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(resp.body) return data end |
.updateMerchant(merchId, merchant) ⇒ Object
Updates an existing Merchant
Parameters: MerchantId, MerchantHash
MerchantHash format is as follows: { “name”: “string”, “address”: { “street_number”: “string”, “street_name”: “string”, “city”: “string”, “state”: “string”, “zip”: “string”, }, “geocode”: { “lat”: 0, “lng”: 0, } } Returns http response code
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/capital_one/merchant.rb', line 73 def self.updateMerchant(merchId, merchant) merchantToUpdate = merchant.to_json url = "#{self.urlWithEntity}/#{merchId}?key=#{self.apiKey}" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) key = "?key=#{self.apiKey}" request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'}) request.body = merchantToUpdate response = http.request(request) return JSON.parse(response.body) end |