-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from WebGents/rebuild_http
Rebuild http
- Loading branch information
Showing
28 changed files
with
190 additions
and
371 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
AllCops: | ||
Exclude: | ||
- bin/* | ||
|
||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
Metrics/BlockLength: | ||
Enabled: false | ||
|
||
Metrics/ClassLength: | ||
Enabled: false | ||
|
||
Metrics/LineLength: | ||
Enabled: false | ||
|
||
Metrics/MethodLength: | ||
Enabled: false | ||
|
||
Metrics/ModuleLength: | ||
Enabled: false | ||
|
||
Metrics/CyclomaticComplexity: | ||
Max: 20 | ||
|
||
Layout/IndentationWidth: | ||
Width: 4 | ||
|
||
Layout/CaseIndentation: | ||
EnforcedStyle: case | ||
SupportedStyles: | ||
- case | ||
- end | ||
IndentOneStep: true | ||
|
||
Layout/AlignHash: | ||
Enabled: false | ||
|
||
Style/GuardClause: | ||
Enabled: false | ||
|
||
Style/FileName: | ||
Enabled: false | ||
|
||
Style/FormatStringToken: | ||
EnforcedStyle: template |
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
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 |
---|---|---|
|
@@ -3,4 +3,4 @@ require 'rspec/core/rake_task' | |
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec | ||
task default: :spec |
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
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,17 +1,15 @@ | ||
module Mobilepay | ||
class Client | ||
# Reservations_CancelReservation | ||
module CancelReservation | ||
|
||
# Reservations_CancelReservation | ||
# Cancels a specific reservation | ||
def cancel_reservation(args = {}) | ||
check_args(order_id: args[:order_id]) | ||
response = call(:delete, "/reservations/merchants/#{merchant_id}/orders/#{args[:order_id]}", { body: '' }) | ||
JSON.parse(response.body) | ||
response = request(:delete, "/reservations/merchants/#{merchant_id}/orders/#{args[:order_id]}") | ||
response.parsed_response | ||
rescue Failure => ex | ||
return { error: ex.message } | ||
end | ||
|
||
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,17 +1,16 @@ | ||
module Mobilepay | ||
class Client | ||
# Reservations_CaptureAmount | ||
module CaptureAmount | ||
|
||
# Reservations_CaptureAmount | ||
# Captures a previously reserved amount, either in full or partially | ||
def capture_amount(args = {}) | ||
check_args(order_id: args[:order_id]) | ||
response = call(:put, "/reservations/merchants/#{merchant_id}/orders/#{args[:order_id]}", { body: args[:body] || '' }) | ||
JSON.parse(response.body) | ||
@body = args[:body] | ||
response = request(:put, "/reservations/merchants/#{merchant_id}/orders/#{args[:order_id]}") | ||
response.parsed_response | ||
rescue Failure => ex | ||
return { error: ex.message } | ||
end | ||
|
||
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,17 +1,15 @@ | ||
module Mobilepay | ||
class Client | ||
# Merchants_GetPaymentStatus | ||
module PaymentStatus | ||
|
||
# Merchants_GetPaymentStatus | ||
# Gets the status of a given order | ||
def payment_status(args = {}) | ||
check_args(order_id: args[:order_id]) | ||
response = call(:get, "/merchants/#{merchant_id}/orders/#{args[:order_id]}", { body: '' }) | ||
JSON.parse(response.body) | ||
response = request(:get, "/merchants/#{merchant_id}/orders/#{args[:order_id]}") | ||
response.parsed_response | ||
rescue Failure => ex | ||
return { error: ex.message } | ||
end | ||
|
||
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,17 +1,15 @@ | ||
module Mobilepay | ||
class Client | ||
# Merchants_GetPaymentTransactions | ||
module PaymentTransactions | ||
|
||
# Merchants_GetPaymentTransactions | ||
# Gets the transactions for a given order | ||
def payment_transactions(args = {}) | ||
check_args(order_id: args[:order_id]) | ||
response = call(:get, "/merchants/#{merchant_id}/orders/#{args[:order_id]}/transactions", { body: '' }) | ||
JSON.parse(response.body) | ||
response = request(:get, "/merchants/#{merchant_id}/orders/#{args[:order_id]}/transactions") | ||
response.parsed_response | ||
rescue Failure => ex | ||
return { error: ex.message } | ||
end | ||
|
||
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,17 +1,16 @@ | ||
module Mobilepay | ||
class Client | ||
# Merchants_RefundAmount | ||
module RefundAmount | ||
|
||
# Merchants_RefundAmount | ||
# Refunds an amount to the customer based on an order id | ||
def refund_amount(args = {}) | ||
check_args(order_id: args[:order_id]) | ||
response = call(:put, "/merchants/#{merchant_id}/orders/#{args[:order_id]}", { body: args[:body] || '{}' }) | ||
JSON.parse(response.body) | ||
@body = args[:body] | ||
response = request(:put, "/merchants/#{merchant_id}/orders/#{args[:order_id]}") | ||
response.parsed_response | ||
rescue Failure => ex | ||
return { error: ex.message } | ||
end | ||
|
||
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,19 +1,17 @@ | ||
module Mobilepay | ||
class Client | ||
# Reservations_GetReservations | ||
module Reservations | ||
|
||
# Reservations_GetReservations | ||
# Get the reservations for a particular date/time interval, and alternatively also for a specific customer | ||
def reservations(args = {}) | ||
check_args(datetime_from: args[:datetime_from], datetime_to: args[:datetime_to]) | ||
address = "/reservations/merchants/#{merchant_id}/#{args[:datetime_from]}/#{args[:datetime_to]}" | ||
address += "?customerId=#{args[:customer_id]}" if args[:customer_id] | ||
response = call(:get, address, { body: '{}' }) | ||
JSON.parse(response.body) | ||
uri = "/reservations/merchants/#{merchant_id}/#{args[:datetime_from]}/#{args[:datetime_to]}" | ||
uri += "?customerId=#{args[:customer_id]}" if args[:customer_id] | ||
response = request(:get, uri) | ||
response.parsed_response | ||
rescue Failure => ex | ||
return { error: ex.message } | ||
end | ||
|
||
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,37 +1,30 @@ | ||
require 'net/http' | ||
|
||
module Mobilepay | ||
# Common requests for classes | ||
module Requests | ||
|
||
private | ||
|
||
def http_request(req, address, args = {}) | ||
uri = generate_uri(address) | ||
req = generate_request(req, uri) | ||
req = generate_headers(req, args[:body]) | ||
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) } | ||
private def request(type, uri) | ||
add_signature(uri) | ||
response = send_request(type, uri) | ||
check_response(response) | ||
response | ||
end | ||
|
||
def generate_uri(address = '') | ||
URI("#{base_uri}#{address}") | ||
private def add_signature(uri) | ||
headers['AuthenticationSignature'] = generate_signature(uri) | ||
end | ||
|
||
def generate_request(req, uri) | ||
case req | ||
when :get then Net::HTTP::Get.new(uri) | ||
when :put then Net::HTTP::Put.new(uri) | ||
when :delete then Net::HTTP::Delete.new(uri) | ||
private def send_request(type, uri) | ||
case type | ||
when :get then self.class.get(uri, query: {}, headers: headers) | ||
when :put then self.class.put(uri, query: {}, headers: headers) | ||
when :delete then self.class.delete(uri, query: {}, headers: headers) | ||
end | ||
end | ||
|
||
def generate_headers(req, body) | ||
req['Content-Type'] = 'application/json' | ||
req['Ocp-Apim-Subscription-Key'] = subscription_key | ||
req['AuthenticationSignature'] = generate_signature(req) unless privatekey.nil? | ||
req['Test-mode'] = test_mode if test_mode == true | ||
req.body = body | ||
req | ||
private def check_response(response) | ||
if response.code != 200 | ||
error_message = response.message.empty? ? response.code : response.message | ||
raise Failure, error_message | ||
end | ||
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
Oops, something went wrong.