-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
166 additions
and
58 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
/lib/mpayer_ruby/support/fake_mpayer/**/*.json |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,42 @@ | ||
module Mpayer | ||
class Fetch | ||
include HTTParty | ||
# base_uri "http://beta.json-generator.com" | ||
base_uri "https://app.mpayer.co.ke/api/" | ||
parser proc {|data| Hashie::Mash.new(response: (JSON.parse(data) rescue {data:data}.to_json) ).response} | ||
format :json | ||
headers | ||
|
||
class << self | ||
def headers | ||
Mpayer.configuration.header.merge!(super) | ||
end | ||
|
||
%w(get put post delete).each do |m| | ||
define_method m do |path, options={}, &block| | ||
res = perform_request Net::HTTP::Put, path, options, &block if m == 'put' | ||
res = perform_request Net::HTTP::Get, path, options, &block if m == 'get' | ||
res = perform_request Net::HTTP::Post, path, options, &block if m == 'post' | ||
res = perform_request Net::HTTP::Delete, path, options, &block if m == 'delete' | ||
save_json(res) if load_json? | ||
res | ||
end | ||
end | ||
|
||
def save_json(response) | ||
request_method = response.request.http_method.name.split('::').last.upcase | ||
file_path = response.request.path.to_s | ||
slash,model,*file_name = file_path.split('/') | ||
file_location = "lib/mpayer_ruby/support/fake_mpayer/#{model}/#{request_method}_#{file_name.join('_')}.json" | ||
File.write(file_location, response.body) | ||
end | ||
|
||
def load_json? | ||
# load JSON if WebMock is off while testing and only in local env with load mpayer turned on | ||
defined?(WebMock).nil? and ENV['CI_TEST'].nil? and defined?(Minitest) and ENV['LOAD_MPAYER'] == "true" | ||
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,25 @@ | ||
require 'sinatra/base' | ||
require 'tilt/erb' | ||
|
||
class FakeMpayer < Sinatra::Base | ||
|
||
[ :get, :post, :put, :delete ].each do |method| | ||
send method, /.*/ do | ||
if (request.env['HTTP_X_WSSE'].empty? rescue true) | ||
[200, {}, [{base:["Authentication Failed"]}.to_json]] | ||
else | ||
slash,api,model,*path = request.path_info.split('/') | ||
json_response 200, "#{model}/#{request.request_method}_#{path.join('_')}.json" | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def json_response(response_code, file_name) | ||
content_type :json | ||
status response_code | ||
headers "content-type"=>["application/json; charset=utf-8"] | ||
erb File.open(File.dirname(__FILE__) + '/fake_mpayer/' + file_name, 'rb').read | ||
end | ||
end |
Empty file.
Empty file.
Empty file.
Empty file.
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,3 @@ | ||
module Mpayer | ||
VERSION = "0.0.08" | ||
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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,16 @@ | ||
require 'test_helper' | ||
|
||
class TestMpayerFetch < Minitest::Test | ||
def test_unauthorised | ||
# skip | ||
url = "/clients/12345" | ||
request = Mpayer::Fetch.get(url,headers:{"X-WSSE"=>""}) | ||
assert(request.base, "Failure message.") | ||
assert_equal(["Authentication Failed"], request.base) | ||
|
||
url = "/clients/12345" | ||
request = Mpayer::Fetch.get(url,headers:{}) | ||
assert(request.base, "Failure message.") | ||
assert_equal(["Authentication Failed"], request.base) | ||
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,17 @@ | ||
require 'rubygems' | ||
require 'pry' | ||
require "pry-alias" | ||
require 'mpayer_ruby' | ||
|
||
Mpayer.setup do |config| | ||
config.user_no = ENV['MPAYER_USER'] | ||
config.token = ENV['MPAYER_TOKEN'] | ||
end | ||
|
||
def save_json(response) | ||
request_method = response.request.http_method.name.split('::').last.upcase | ||
file_path = response.request.path.to_s | ||
slash,model,*file_name = file_path.split('/') | ||
file_location = "test/support/fake_mpayer/#{model}/#{request_method}_#{file_name.join('_')}.json" | ||
File.write(file_location, response.body) | ||
end |
File renamed without changes.
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