globe_labs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +24 -0
- data/README.md +144 -0
- data/globe_labs.gemspec +26 -0
- data/lib/globe_labs.rb +6 -0
- data/lib/globe_labs/client.rb +66 -0
- data/lib/globe_labs/errors/authentication_error.rb +4 -0
- data/lib/globe_labs/errors/client_error.rb +4 -0
- data/lib/globe_labs/errors/error.rb +4 -0
- data/lib/globe_labs/errors/server_error.rb +4 -0
- data/lib/globe_labs/main.rb +84 -0
- data/lib/globe_labs/params.rb +14 -0
- data/lib/globe_labs/version.rb +3 -0
- data/spec/globe_labs/client_spec.rb +158 -0
- data/spec/globe_labs/main_spec.rb +31 -0
- data/spec/globe_labs/params_spec.rb +18 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 55859d8078c4e07000654daa1208f527f429ef8c
|
4
|
+
data.tar.gz: ce4c70b01684d27ba9c0c0b955a131e7c2433da2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccb8147e289d1939d9fdc27081dbc983a3ed156d4140c3cd4a8fd75b788c3e294c0d586fc419d52177ff1708401326f8220505ae9814931fc98310ab67ded409
|
7
|
+
data.tar.gz: 81ac64af6977f6ba7fc52983506fbe93e67da7c1d2a97036d81a99e6f6d8f83bc741eae59b7b452ad8cad42f5a0df7abff2a453114b87a886ed56e0a9e4aa910
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Nexmo Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
6
|
+
obtaining a copy of this software and associated documentation
|
7
|
+
files (the "Software"), to deal in the Software without
|
8
|
+
restriction, including without limitation the rights to use,
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the
|
11
|
+
Software is furnished to do so, subject to the following
|
12
|
+
conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# globelabs
|
2
|
+
Ruby wrapper for [GlobeLabs](http://www.globelabs.com.ph/) API
|
3
|
+
|
4
|
+
|
5
|
+
Add to Gemfile
|
6
|
+
```ruby
|
7
|
+
gem 'globelabs'
|
8
|
+
```
|
9
|
+
then
|
10
|
+
|
11
|
+
$ bundle install
|
12
|
+
|
13
|
+
or
|
14
|
+
|
15
|
+
$ gem install globelabs
|
16
|
+
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
#### Initialize
|
20
|
+
```ruby
|
21
|
+
require 'globelabs'
|
22
|
+
|
23
|
+
globelabs = GlobeLabs::Client.new(key: 'app_id', secret: 'app_secret', send_address: 'short_code')
|
24
|
+
```
|
25
|
+
|
26
|
+
#### [Get Access Token](http://www.globelabs.com.ph/docs/#getting-started-opt-in-via-webform)
|
27
|
+
_note: skip this part if you already have the access token_
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
globelabs.get_access_token(code)
|
31
|
+
|
32
|
+
# =>
|
33
|
+
# {
|
34
|
+
# "access_token":"1ixLbltjWkzwqLMXT-8UF-UQeKRma0hOOWFA6o91oXw",
|
35
|
+
# "subscriber_number":"9171234567"
|
36
|
+
# }
|
37
|
+
```
|
38
|
+
|
39
|
+
#### [Send Message](http://www.globelabs.com.ph/docs/#sms-sending-sms-sms-mt)
|
40
|
+
Send an SMS message to one or more mobile terminals:
|
41
|
+
```ruby
|
42
|
+
globelabs.send_message(token, subscriber_number, message)
|
43
|
+
|
44
|
+
# =>
|
45
|
+
# {
|
46
|
+
# "outboundSMSMessageRequest": {
|
47
|
+
# "address": "tel:+639175595283",
|
48
|
+
# "deliveryInfoList": {
|
49
|
+
# "deliveryInfo": [],
|
50
|
+
# "resourceURL": "https://devapi.globelabs.com.ph/smsmessaging/v1/outbound/8011/requests?access_token=3YM8xurK_IPdhvX4OUWXQljcHTIPgQDdTESLXDIes4g"
|
51
|
+
# },
|
52
|
+
# "senderAddress": "8011",
|
53
|
+
# "outboundSMSTextMessage": {
|
54
|
+
# "message": "Hello World"
|
55
|
+
# },
|
56
|
+
# "receiptRequest": {
|
57
|
+
# "notifyURL": "http://test-sms1.herokuapp.com/callback",
|
58
|
+
# "callbackData": null,
|
59
|
+
# "senderName": null,
|
60
|
+
# "resourceURL": "https://devapi.globelabs.com.ph/smsmessaging/v1/outbound/8011/requests?access_token=3YM8xurK_IPdhvX4OUWXQljcHTIPgQDdTESLXDIes4g"
|
61
|
+
# }
|
62
|
+
# }
|
63
|
+
# }
|
64
|
+
```
|
65
|
+
|
66
|
+
#### [Locate](http://www.globelabs.com.ph/docs/#location-based-services-resources-and-uris)
|
67
|
+
Locate a subscriber’s location:
|
68
|
+
```ruby
|
69
|
+
globelabs.locate(token, subscriber_number)
|
70
|
+
|
71
|
+
# =>
|
72
|
+
# {
|
73
|
+
# "terminalLocationList": {
|
74
|
+
# "terminalLocation": {
|
75
|
+
# "address": "tel:9171234567",
|
76
|
+
# "currentLocation": {
|
77
|
+
# "accuracy": 100,
|
78
|
+
# "latitude": "14.5609722",
|
79
|
+
# "longitude": "121.0193394",
|
80
|
+
# "map_url": "http://maps.google.com/maps?z=17&t=m&q=loc:14.5609722+121.0193394",
|
81
|
+
# "timestamp": "Fri Jun 06 2014 09:25:15 GMT+0000 (UTC)"
|
82
|
+
# },
|
83
|
+
# "locationRetrievalStatus": "Retrieved"
|
84
|
+
# }
|
85
|
+
# }
|
86
|
+
# }
|
87
|
+
```
|
88
|
+
|
89
|
+
#### [Charge](http://www.globelabs.com.ph/docs/#charging-charge-subscriber)
|
90
|
+
Charge/bill a subscriber:
|
91
|
+
```ruby
|
92
|
+
options = {
|
93
|
+
amount: "20",
|
94
|
+
description: "sample description",
|
95
|
+
endUserId: "915xxxxxxx",
|
96
|
+
reference_code: '1234567',
|
97
|
+
transactionOperationStatus: 'Charged'
|
98
|
+
}
|
99
|
+
|
100
|
+
globelabs.charge(token, options)
|
101
|
+
|
102
|
+
# =>
|
103
|
+
# {
|
104
|
+
# "amountTransaction":
|
105
|
+
# {
|
106
|
+
# "endUserId": "9171234567",
|
107
|
+
# "paymentAmount":
|
108
|
+
# {
|
109
|
+
# "chargingInformation":
|
110
|
+
# {
|
111
|
+
# "amount": "0.00",
|
112
|
+
# "currency": "PHP",
|
113
|
+
# "description": "my application"
|
114
|
+
# },
|
115
|
+
# "totalAmountCharged": "0.00"
|
116
|
+
# },
|
117
|
+
# "referenceCode": "12341000023",
|
118
|
+
# "serverReferenceCode": "528f5369b390e16a62000006",
|
119
|
+
# "resourceURL": null
|
120
|
+
# }
|
121
|
+
# }
|
122
|
+
```
|
123
|
+
|
124
|
+
#### [Last Reference Code](http://www.globelabs.com.ph/docs/#charging-get-last-reference-code)
|
125
|
+
In case you lost of track of your reference code:
|
126
|
+
```ruby
|
127
|
+
globelabs.last_reference_code
|
128
|
+
|
129
|
+
# =>
|
130
|
+
# {
|
131
|
+
# "referenceCode": "12341000005",
|
132
|
+
# "status": "SUCCESS",
|
133
|
+
# "shortcode": "21581234"
|
134
|
+
# }
|
135
|
+
```
|
136
|
+
|
137
|
+
|
138
|
+
## Contributing
|
139
|
+
|
140
|
+
1. Fork it ( https://github.com/jaemar/globelabs/fork )
|
141
|
+
2. Create your feature branch (`git checkout -b feature/new_feature`)
|
142
|
+
3. Commit your changes (`git commit -am 'Add new feature'`)
|
143
|
+
4. Push to the branch (`git push origin feature/new_feature`)
|
144
|
+
5. Create a new Pull Request
|
data/globe_labs.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('lib/globe_labs/version', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'globe_labs'
|
5
|
+
s.version = GlobeLabs::VERSION
|
6
|
+
s.license = 'MIT'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Jaemar Ramos']
|
9
|
+
s.email = ['jaemar.ramos@gmail.com']
|
10
|
+
s.description = 'Globe Labs Client Library for Ruby'
|
11
|
+
s.summary = 'Ruby client library for Globe Labs\' API.'
|
12
|
+
s.required_ruby_version = '>= 1.9.3'
|
13
|
+
|
14
|
+
s.add_development_dependency('rake')
|
15
|
+
s.add_development_dependency('minitest', '~> 5.0')
|
16
|
+
|
17
|
+
if RUBY_VERSION == '1.9.3'
|
18
|
+
s.add_development_dependency('addressable', '< 2.5.0')
|
19
|
+
s.add_development_dependency('webmock', '~> 1.0')
|
20
|
+
else
|
21
|
+
s.add_development_dependency('webmock', '~> 2.0')
|
22
|
+
end
|
23
|
+
|
24
|
+
s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md globe_labs.gemspec)
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
end
|
data/lib/globe_labs.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module GlobeLabs
|
2
|
+
class Client < Main
|
3
|
+
def send_message(token, number, message)
|
4
|
+
post(@api_host, send_sms_uri(token), build_send_message_params(number, message), 'json')
|
5
|
+
end
|
6
|
+
|
7
|
+
def locate(token, number)
|
8
|
+
get(@api_host, locate_uri, build_locate_params(token, number), 'json')
|
9
|
+
end
|
10
|
+
|
11
|
+
def charge(token, options = {})
|
12
|
+
post(@api_host, charge_uri(token), build_charge_params(options))
|
13
|
+
end
|
14
|
+
|
15
|
+
def last_reference_code
|
16
|
+
get(@api_host, reference_code_uri, {app_id: @key,
|
17
|
+
app_secret: @secret})
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def send_sms_uri(token)
|
22
|
+
"/smsmessaging/#{@version}/outbound/#{@short_code}/requests?access_token=#{token}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_send_message_params(number, message)
|
26
|
+
{
|
27
|
+
"outboundSMSMessageRequest": {
|
28
|
+
"clientCorrelator": "#{rand(10 ** 6)}",
|
29
|
+
"senderAddress": "#{@short_code}",
|
30
|
+
"outboundSMSTextMessage": {"message": "#{message}"},
|
31
|
+
"address": "tel:+63#{number}"
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def locate_uri
|
37
|
+
"/location/#{@version}/queries/location"
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_locate_params(token, number)
|
41
|
+
{
|
42
|
+
"access_token": token,
|
43
|
+
"address": "0#{number}",
|
44
|
+
"requestedAccuracy": "100"
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def charge_uri(token)
|
49
|
+
"/payment/v1/transactions/amount?access_token=#{token}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def build_charge_params(options)
|
53
|
+
{
|
54
|
+
amount: options[:amount],
|
55
|
+
description: options[:description],
|
56
|
+
endUserId: "tel:+63#{options[:endUserId]}",
|
57
|
+
referenceCode: "#{@short_code}#{options[:referenceCode]}",
|
58
|
+
transactionOperationStatus: 'Charged'
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def reference_code_uri
|
63
|
+
'/payment/v1/transactions/getLastRefCode'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module GlobeLabs
|
6
|
+
class Main
|
7
|
+
attr_accessor :key, :secret, :access_token
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
@key = options.fetch(:key)
|
11
|
+
@secret = options.fetch(:secret)
|
12
|
+
@short_code = options[:sender_address]
|
13
|
+
@auth_host = options.fetch(:auth_host) { 'developer.globelabs.com.ph' }
|
14
|
+
@api_host = options.fetch(:api_host) { 'devapi.globelabs.com.ph' }
|
15
|
+
@version = options.fetch(:version) { 'v1' }
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_access_token(code)
|
19
|
+
post(@auth_host, '/oauth/access_token', {app_id: @key,
|
20
|
+
app_secret: @secret,
|
21
|
+
code: code})
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def get(host, request_uri, params = {}, content_type = 'x-www-form-urlencoded')
|
26
|
+
uri = URI('https://' + host + request_uri)
|
27
|
+
uri.query = Params.encode(params)
|
28
|
+
|
29
|
+
message = Net::HTTP::Get.new(uri.request_uri, 'Content-Type' => "application/#{content_type}")
|
30
|
+
|
31
|
+
case content_type
|
32
|
+
when 'json'
|
33
|
+
message.body = params.to_json
|
34
|
+
else
|
35
|
+
message.form_data = params
|
36
|
+
end
|
37
|
+
|
38
|
+
request(uri, message)
|
39
|
+
end
|
40
|
+
|
41
|
+
def post(host, request_uri, params, content_type = 'x-www-form-urlencoded')
|
42
|
+
uri = URI('https://' + host + request_uri)
|
43
|
+
message = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => "application/#{content_type}")
|
44
|
+
|
45
|
+
case content_type
|
46
|
+
when 'json'
|
47
|
+
message.body = params.to_json
|
48
|
+
else
|
49
|
+
message.form_data = params
|
50
|
+
end
|
51
|
+
|
52
|
+
request(uri, message)
|
53
|
+
end
|
54
|
+
|
55
|
+
def request(uri, message)
|
56
|
+
http = Net::HTTP.new(uri.host, Net::HTTP.https_default_port)
|
57
|
+
http.use_ssl = true
|
58
|
+
|
59
|
+
http_response = http.request(message)
|
60
|
+
|
61
|
+
case http_response
|
62
|
+
when Net::HTTPNoContent
|
63
|
+
:no_content
|
64
|
+
when Net::HTTPSuccess
|
65
|
+
return (yield http_response) if block_given?
|
66
|
+
|
67
|
+
if http_response['Content-Type'].split(';').first == 'application/json'
|
68
|
+
JSON.parse(http_response.body)
|
69
|
+
else
|
70
|
+
http_response.body
|
71
|
+
end
|
72
|
+
when Net::HTTPUnauthorized
|
73
|
+
raise AuthenticationError, "#{http_response.code} response from #{uri.host}"
|
74
|
+
when Net::HTTPClientError
|
75
|
+
http_response.body
|
76
|
+
#raise ClientError, "#{http_response.code} response from #{uri.host}"
|
77
|
+
when Net::HTTPServerError
|
78
|
+
raise ServerError, "#{http_response.code} response from #{uri.host}"
|
79
|
+
else
|
80
|
+
raise Error, "#{http_response.code} response from #{uri.host}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module GlobeLabs
|
4
|
+
module Params
|
5
|
+
def self.encode(params)
|
6
|
+
params.flat_map { |k, vs| Array(vs).map { |v| "#{escape(k)}=#{escape(v)}" } }.join('&')
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
def self.escape(component)
|
11
|
+
CGI.escape(component.to_s)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'webmock/minitest'
|
3
|
+
require 'globe_labs'
|
4
|
+
|
5
|
+
|
6
|
+
describe 'GlobeLabs::Client' do
|
7
|
+
before do
|
8
|
+
@key = 'key'
|
9
|
+
@secret = 'secret'
|
10
|
+
@short_code = '1234'
|
11
|
+
@token = 'token'
|
12
|
+
@number = '9951234567'
|
13
|
+
@message = 'your sample message'
|
14
|
+
@globe = GlobeLabs::Client.new(key: @key, secret: @secret, short_code: @short_code)
|
15
|
+
@api_host = 'https://devapi.globelabs.com.ph'
|
16
|
+
@response_body = {body: {key: 'value'}.to_json, headers: {'Content-Type' => 'application/json;charset=utf-8'}}
|
17
|
+
@response_object = {"key" => 'value'}
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO SEND MESSAGE
|
21
|
+
describe '#send_message' do
|
22
|
+
it 'returns response object' do
|
23
|
+
random = rand(10 ** 6)
|
24
|
+
body = {
|
25
|
+
"outboundSMSMessageRequest": {
|
26
|
+
"clientCorrelator": "#{random}",
|
27
|
+
"senderAddress": "#{@short_code}",
|
28
|
+
"outboundSMSTextMessage": {"message": "#{@message}"},
|
29
|
+
"address": "tel:+63#{@number}"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
@globe.stub(:rand, random) do
|
33
|
+
stub_post("#@api_host/smsmessaging/v1/outbound/#@short_code/requests?access_token=#@token", body.to_json, 'json')
|
34
|
+
@globe.send_message(@token, @number, @message).must_equal @response_object
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#send_sms_uri' do
|
40
|
+
it 'returns send_sms_uri' do
|
41
|
+
@globe.send(:send_sms_uri, @token).must_equal '/smsmessaging/v1/outbound/1234/requests?access_token=token'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#build_send_message_params' do
|
46
|
+
it 'returns build_send_message_params' do
|
47
|
+
response_object = {
|
48
|
+
outboundSMSMessageRequest: {
|
49
|
+
clientCorrelator: "123456",
|
50
|
+
senderAddress: "1234",
|
51
|
+
outboundSMSTextMessage: { message: "your sample message" },
|
52
|
+
address: "tel:+63#{@number}"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
@globe.stub(:rand, 123456) do
|
57
|
+
@globe.send(:build_send_message_params, @number, @message).must_equal response_object
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# LOCATE
|
63
|
+
describe '#locate' do
|
64
|
+
it 'fetch user current location' do
|
65
|
+
stub_get("#@api_host/location/v1/queries/location?access_token=#@token&address=0#@number&requestedAccuracy=100", 'json')
|
66
|
+
@globe.locate(@token, @number).must_equal @response_object
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#locate_uri' do
|
71
|
+
it 'returns locate_uri' do
|
72
|
+
@globe.send(:locate_uri).must_equal '/location/v1/queries/location'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#build_locate_params' do
|
77
|
+
it 'returns build_locate_params' do
|
78
|
+
response_object = {
|
79
|
+
access_token: @token,
|
80
|
+
address: "0#{@number}",
|
81
|
+
requestedAccuracy: "100"
|
82
|
+
}
|
83
|
+
@globe.send(:build_locate_params, @token, @number).must_equal response_object
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# CHARGE
|
88
|
+
describe '#charge' do
|
89
|
+
it 'returns response object' do
|
90
|
+
options = {
|
91
|
+
amount: "100",
|
92
|
+
description: 'sample description',
|
93
|
+
endUserId: "#{@number}",
|
94
|
+
referenceCode: "1234567",
|
95
|
+
transactionOperationStatus: 'Charged'
|
96
|
+
}
|
97
|
+
|
98
|
+
body = "amount=100&description=sample description&endUserId=tel:%2B63#@number&referenceCode=#{@short_code}1234567&transactionOperationStatus=Charged"
|
99
|
+
|
100
|
+
stub_post("#@api_host/payment/v1/transactions/amount?access_token=#@token", body)
|
101
|
+
@globe.charge(@token, options).must_equal @response_object
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#charge_uri' do
|
106
|
+
it 'returns charge_uri' do
|
107
|
+
@globe.send(:charge_uri, 'token').must_equal '/payment/v1/transactions/amount?access_token=token'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#build_charge_params' do
|
112
|
+
it 'returns build_charge_params' do
|
113
|
+
params = {
|
114
|
+
amount: 100,
|
115
|
+
description: "description",
|
116
|
+
endUserId: @number,
|
117
|
+
referenceCode: "1234567",
|
118
|
+
transactionOperationStatus: 'Charged'
|
119
|
+
}
|
120
|
+
|
121
|
+
response_object = {
|
122
|
+
amount: 100,
|
123
|
+
description: "description",
|
124
|
+
endUserId: "tel:+63#{@number}",
|
125
|
+
referenceCode: "#{@short_code}1234567",
|
126
|
+
transactionOperationStatus: 'Charged'
|
127
|
+
}
|
128
|
+
|
129
|
+
@globe.send(:build_charge_params, params).must_equal response_object
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# REFERENCE_CODE
|
134
|
+
describe '#last_reference_code' do
|
135
|
+
it 'fetch last reference code (charge)' do
|
136
|
+
stub_get("#@api_host/payment/v1/transactions/getLastRefCode?app_id=#@key&app_secret=#@secret")
|
137
|
+
@globe.last_reference_code.must_equal @response_object
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
describe '#reference_code_uri' do
|
142
|
+
it 'returns reference_code_uri' do
|
143
|
+
@globe.send(:reference_code_uri).must_equal '/payment/v1/transactions/getLastRefCode'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
def stub_get(url, content_type = 'x-www-form-urlencoded')
|
149
|
+
headers = {'Content_type' => "application/#{content_type}"}
|
150
|
+
@request = stub_request(:get, url).with(headers: headers).to_return(@response_body)
|
151
|
+
end
|
152
|
+
|
153
|
+
def stub_post(url, body, content_type = 'x-www-form-urlencoded')
|
154
|
+
headers = {'Content_type' => "application/#{content_type}"}
|
155
|
+
body = WebMock::Util::QueryMapper.query_to_values(body) unless content_type == 'json'
|
156
|
+
@request = stub_request(:post, url).with(body: body, headers: headers).to_return(@response_body)
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'webmock/minitest'
|
3
|
+
require 'globe_labs'
|
4
|
+
|
5
|
+
describe 'GlobeLabs::Main' do
|
6
|
+
before do
|
7
|
+
@key = 'key'
|
8
|
+
@secret = 'secret'
|
9
|
+
@short_code = '1234'
|
10
|
+
@globe = GlobeLabs::Client.new(key: @key, secret: @secret, short_code: @short_code)
|
11
|
+
@code = 'code'
|
12
|
+
@auth_host = 'https://developer.globelabs.com.ph'
|
13
|
+
@response_body = {body: {key: 'value'}.to_json, headers: {'Content-Type' => 'application/json;charset=utf-8'}}
|
14
|
+
@response_object = {"key" => 'value'}
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#get_access_token' do
|
18
|
+
it 'returns access token and subscriber' do
|
19
|
+
body = "app_id=#@key&app_secret=#@secret&code=#@code"
|
20
|
+
stub_post("#@auth_host/oauth/access_token", body)
|
21
|
+
@globe.get_access_token(@code).must_equal @response_object
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def stub_post(url, body)
|
27
|
+
headers = {'Content_type' => "application/x-www-form-urlencoded"}
|
28
|
+
body = WebMock::Util::QueryMapper.query_to_values(body)
|
29
|
+
@request = stub_request(:post, url).with(body: body, headers: headers).to_return(@response_body)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'globe_labs'
|
3
|
+
|
4
|
+
describe 'GlobeLabs::Params' do
|
5
|
+
describe 'encode method' do
|
6
|
+
it 'returns a url encoded string containing the given params' do
|
7
|
+
params = {app_id: 'key', secret: 'secret', short_code: '1234'}
|
8
|
+
|
9
|
+
GlobeLabs::Params.encode(params).must_equal('app_id=key&secret=secret&short_code=1234')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'flattens array values into multiple key value pairs' do
|
13
|
+
params = {'ids' => %w[001A 001B 001C]}
|
14
|
+
|
15
|
+
GlobeLabs::Params.encode(params).must_equal('ids=001A&ids=001B&ids=001C')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: globe_labs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jaemar Ramos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
description: Globe Labs Client Library for Ruby
|
56
|
+
email:
|
57
|
+
- jaemar.ramos@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- README.md
|
64
|
+
- globe_labs.gemspec
|
65
|
+
- lib/globe_labs.rb
|
66
|
+
- lib/globe_labs/client.rb
|
67
|
+
- lib/globe_labs/errors/authentication_error.rb
|
68
|
+
- lib/globe_labs/errors/client_error.rb
|
69
|
+
- lib/globe_labs/errors/error.rb
|
70
|
+
- lib/globe_labs/errors/server_error.rb
|
71
|
+
- lib/globe_labs/main.rb
|
72
|
+
- lib/globe_labs/params.rb
|
73
|
+
- lib/globe_labs/version.rb
|
74
|
+
- spec/globe_labs/client_spec.rb
|
75
|
+
- spec/globe_labs/main_spec.rb
|
76
|
+
- spec/globe_labs/params_spec.rb
|
77
|
+
homepage:
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.9.3
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.6.13
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Ruby client library for Globe Labs' API.
|
101
|
+
test_files: []
|