open_market 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +7 -0
- data/README.md +39 -0
- data/lib/open_market/base.rb +42 -0
- data/lib/open_market/response.rb +91 -0
- data/lib/open_market.rb +7 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/unit/open_market/response_spec.rb +75 -0
- metadata +68 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2010 Aleksey Gureiev and Recess Mobile, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
Open Market integration kit
|
2
|
+
===========================
|
3
|
+
|
4
|
+
Open Market integration kit is intended to help working with the Open Market API
|
5
|
+
from your Ruby applications.
|
6
|
+
|
7
|
+
To use the kit, you need to be a registered user of Open Market (http://openmarket.com)
|
8
|
+
and have Account ID and Account Password.
|
9
|
+
|
10
|
+
|
11
|
+
Installation
|
12
|
+
============
|
13
|
+
|
14
|
+
gem install open_market
|
15
|
+
|
16
|
+
|
17
|
+
Usage
|
18
|
+
=====
|
19
|
+
|
20
|
+
om = OpenMarket::Base.new('xxx-xxx-xxx-xxxxx', '<your_account_password>')
|
21
|
+
|
22
|
+
# Looking up details on the phone number
|
23
|
+
res = om.preview('+16123327465')
|
24
|
+
if res.success?
|
25
|
+
res.destination # hash of destination details
|
26
|
+
res.operator # hash of operator details
|
27
|
+
res.location # hash of geographical data
|
28
|
+
else
|
29
|
+
res.error[:code] # error code
|
30
|
+
res.error[:description] # details error description
|
31
|
+
res.error[:resolution] #
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
License
|
36
|
+
=======
|
37
|
+
|
38
|
+
Circuit Breaker is Copyright © 2010 [Aleksey Gureiev](mailto:spyromus@noizeramp.com) and [Recess Mobile](http://recessmobile.com/).
|
39
|
+
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module OpenMarket
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def initialize(account_id, account_password, options = {})
|
5
|
+
@account_id = account_id
|
6
|
+
@account_password = account_password
|
7
|
+
|
8
|
+
@server = options[:server] || 'smsc-01.openmarket.com'
|
9
|
+
@path = options[:path] || '/wmp'
|
10
|
+
end
|
11
|
+
|
12
|
+
def preview(phone_number)
|
13
|
+
request(:type => 'preview', :destination => { :address => phone_number })
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def xml_packet(options = {})
|
19
|
+
d = REXML::Document.new
|
20
|
+
d << REXML::XMLDecl.new
|
21
|
+
|
22
|
+
request = d.add_element 'request', 'version' => "3.0", 'protocol' => "wmp", 'type' => options[:type]
|
23
|
+
request.add_element 'account', 'id' => @account_id, 'password' => @account_password
|
24
|
+
|
25
|
+
if (dest = options[:destination])
|
26
|
+
request.add_element 'destination', 'ton' => (dest[:ton] || 0), 'address' => dest[:address]
|
27
|
+
end
|
28
|
+
|
29
|
+
d.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def request(options = {})
|
33
|
+
response = nil
|
34
|
+
|
35
|
+
Net::HTTP.start(@server) do |q|
|
36
|
+
response = q.post(@path, xml_packet(options), { 'Content-Type' => 'text/xml' }).body
|
37
|
+
end
|
38
|
+
|
39
|
+
Response.new(response)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module OpenMarket
|
2
|
+
class Response
|
3
|
+
|
4
|
+
attr_reader :error, :destination, :location, :operator
|
5
|
+
|
6
|
+
def initialize(xml)
|
7
|
+
@doc = REXML::Document.new(xml)
|
8
|
+
puts xml
|
9
|
+
|
10
|
+
get_error
|
11
|
+
get_destination
|
12
|
+
get_location
|
13
|
+
get_operator
|
14
|
+
end
|
15
|
+
|
16
|
+
def success?
|
17
|
+
@error && @error[:code] == 0
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def get_error
|
23
|
+
el = @doc.root.elements['error']
|
24
|
+
@error = {
|
25
|
+
:code => el.attributes['code'].to_i,
|
26
|
+
:description => el.attributes['description'],
|
27
|
+
:resolution => el.attributes['resolution'] }
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_destination
|
31
|
+
el = @doc.root.elements['destination']
|
32
|
+
return if el.nil?
|
33
|
+
|
34
|
+
@destination = {
|
35
|
+
:country_code => el.attributes['country_code'].to_i,
|
36
|
+
:national_number => el.attributes['national_number'],
|
37
|
+
:intl_notation => el.attributes['intl_notation'],
|
38
|
+
:area_code => el.attributes['area_code'],
|
39
|
+
:area_code_length => el.attributes['area_code_length'].to_i,
|
40
|
+
:num_min_length => el.attributes['num_min_length'].to_i,
|
41
|
+
:num_max_length => el.attributes['num_max_length'].to_i,
|
42
|
+
:na_nxx => el.attributes['na_nxx'],
|
43
|
+
:na_line => el.attributes['na_line'],
|
44
|
+
:local_notation => el.attributes['local_notation'],
|
45
|
+
:local_format => el.attributes['local_format'],
|
46
|
+
:digits_all => el.attributes['digits_all'].to_i,
|
47
|
+
:digits_local => el.attributes['digits_local'].to_i,
|
48
|
+
:ported => el.attributes['ported'] == 'true',
|
49
|
+
:ported_from => el.attributes['ported_from'].to_i }
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_location
|
53
|
+
el = @doc.root.elements['location']
|
54
|
+
return if el.nil?
|
55
|
+
|
56
|
+
@location = {
|
57
|
+
:zone => el.attributes['zone'].to_i,
|
58
|
+
:zone_name => el.attributes['zone_name'],
|
59
|
+
:country => el.attributes['country'],
|
60
|
+
:country_name => el.attributes['country_name'],
|
61
|
+
:region => el.attributes['region'],
|
62
|
+
:region_name => el.attributes['region_name'],
|
63
|
+
:city => el.attributes['city'],
|
64
|
+
:timezone_min => el.attributes['timezone_min'],
|
65
|
+
:timezone_max => el.attributes['timezone_max'],
|
66
|
+
:estimated_latitude => el.attributes['estimated_latitude'],
|
67
|
+
:estimated_longitude => el.attributes['estimated_longitude'] }
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_operator
|
71
|
+
el = @doc.root.elements['operator']
|
72
|
+
return if el.nil?
|
73
|
+
|
74
|
+
@operator = {
|
75
|
+
:id => el.attributes['id'].to_i,
|
76
|
+
:name => el.attributes['name'],
|
77
|
+
:text_length => el.attributes['text_length'].to_i,
|
78
|
+
:binary_length => el.attributes['binary_length'].to_i,
|
79
|
+
:unicode_length => el.attributes['unicode_length'].to_i,
|
80
|
+
:binary => el.attributes['binary'] == 'true',
|
81
|
+
:unicode => el.attributes['unicode'] == 'true',
|
82
|
+
:smart_messaging => el.attributes['smart_messaging'] == 'true',
|
83
|
+
:wap_push => el.attributes['wap_push'] == 'true',
|
84
|
+
:ems => el.attributes['ems'] == 'ems',
|
85
|
+
:price => el.attributes['price'].to_f,
|
86
|
+
:price_currency => el.attributes['price_currency'],
|
87
|
+
:price_plan => el.attributes['price_plan'],
|
88
|
+
:price_tier => el.attributes['price_tier'].to_i }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/open_market.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe OpenMarket::Response do
|
4
|
+
|
5
|
+
describe "when receiving preview responses" do
|
6
|
+
it "should parse successful" do
|
7
|
+
xml = '<?xml version="1.0"?><response version="3.0" protocol="wmp" type="preview"><error code="0" description="No Error" resolution=""/><destination country_code="1" national_number="6147389968" intl_notation="+16147389968" area_code="614" area_code_length="3" num_min_length="7" num_max_length="7" na_nxx="738" na_line="9968" local_notation="(614) 738-9968" local_format="(###) ###-####" digits_all="11" digits_local="10" ported="false" ported_from="0"/><location zone="1" zone_name="North America, Caribbean" country="US" country_name="United States" region="OH" region_name="Ohio" city="Columbus" timezone_min="-5" timezone_max="-5" estimated_latitude="39.96" estimated_longitude="-83.00"/><operator id="77" name="Verizon" text_length="160" binary_length="0" unicode_length="0" binary="false" unicode="false" smart_messaging="false" wap_push="false" ems="false" price="0.0320" price_currency="USD" price_plan="Dedicated" price_tier="1"/></response>'
|
8
|
+
r = OpenMarket::Response.new(xml)
|
9
|
+
r.should be_success
|
10
|
+
|
11
|
+
r.error[:code].should == 0
|
12
|
+
r.error[:description].should == "No Error"
|
13
|
+
r.error[:resolution].should == ""
|
14
|
+
|
15
|
+
d = r.destination
|
16
|
+
d[:country_code].should == 1
|
17
|
+
d[:national_number].should == "6147389968"
|
18
|
+
d[:intl_notation].should == "+16147389968"
|
19
|
+
d[:area_code].should == "614"
|
20
|
+
d[:area_code_length].should == 3
|
21
|
+
d[:num_min_length].should == 7
|
22
|
+
d[:num_max_length].should == 7
|
23
|
+
d[:na_nxx].should == "738"
|
24
|
+
d[:na_line].should == "9968"
|
25
|
+
d[:local_notation].should == "(614) 738-9968"
|
26
|
+
d[:local_format].should == "(###) ###-####"
|
27
|
+
d[:digits_all].should == 11
|
28
|
+
d[:digits_local].should == 10
|
29
|
+
d[:ported].should == false
|
30
|
+
d[:ported_from].should == 0
|
31
|
+
|
32
|
+
l = r.location
|
33
|
+
l[:zone].should == 1
|
34
|
+
l[:zone_name].should == "North America, Caribbean"
|
35
|
+
l[:country].should == "US"
|
36
|
+
l[:country_name].should == "United States"
|
37
|
+
l[:region].should == "OH"
|
38
|
+
l[:region_name].should == "Ohio"
|
39
|
+
l[:city].should == "Columbus"
|
40
|
+
l[:timezone_min].should == "-5"
|
41
|
+
l[:timezone_max].should == "-5"
|
42
|
+
l[:estimated_latitude].should == "39.96"
|
43
|
+
l[:estimated_longitude].should == "-83.00"
|
44
|
+
|
45
|
+
o = r.operator
|
46
|
+
o[:id].should == 77
|
47
|
+
o[:name].should == "Verizon"
|
48
|
+
o[:text_length].should == 160
|
49
|
+
o[:binary_length].should == 0
|
50
|
+
o[:unicode_length].should == 0
|
51
|
+
o[:binary].should == false
|
52
|
+
o[:unicode].should == false
|
53
|
+
o[:smart_messaging].should == false
|
54
|
+
o[:wap_push].should == false
|
55
|
+
o[:ems].should == false
|
56
|
+
o[:price].should == 0.032
|
57
|
+
o[:price_currency].should == "USD"
|
58
|
+
o[:price_plan].should == "Dedicated"
|
59
|
+
o[:price_tier].should == 1
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should parse error" do
|
63
|
+
xml = '<?xml version="1.0"?><response version="3.0" protocol="wmp" type="preview"><error code="345" description="Unable to determine carrier id from pin or destination address." resolution=""/></response>'
|
64
|
+
r = OpenMarket::Response.new(xml)
|
65
|
+
|
66
|
+
r.should_not be_success
|
67
|
+
|
68
|
+
r.error[:code].should == 345
|
69
|
+
r.error[:description].should == "Unable to determine carrier id from pin or destination address."
|
70
|
+
r.error[:resolution].should == ""
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open_market
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Aleksey Gureiev
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-08-17 00:00:00 +03:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: Open Market integration kit
|
21
|
+
email: spyromus@noizeramp.com
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files:
|
27
|
+
- README.md
|
28
|
+
files:
|
29
|
+
- README.md
|
30
|
+
- MIT-LICENSE
|
31
|
+
- lib/open_market/base.rb
|
32
|
+
- lib/open_market/response.rb
|
33
|
+
- lib/open_market.rb
|
34
|
+
- spec/spec_helper.rb
|
35
|
+
- spec/unit/open_market/response_spec.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: ""
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --line-numbers
|
43
|
+
- --inline-source
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project: open_market
|
63
|
+
rubygems_version: 1.3.6
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Open Market integration kit
|
67
|
+
test_files:
|
68
|
+
- spec/unit/open_market/response_spec.rb
|