carrier-services 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrier-services.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Rubin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Carrier::Services
2
+
3
+ Allows you to interact with your carrier via ruby.Often handling the page scraping an all the other nasty.
4
+
5
+ Current supported networks are.
6
+
7
+ 1. MTN
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'carrier-services'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install carrier-services
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carrier_services/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carrier-services"
8
+ spec.version = CarrierServices::VERSION
9
+ spec.authors = ["David Rubin"]
10
+ spec.email = ["davidrub@gmail.com.com"]
11
+ spec.description = %q{Allows you to interact with your carrier via ruby. Often handling the page scraping an all the other nasty}
12
+ spec.summary = %q{Allows you to interact with your carrier via ruby.Often handling the page scraping an all the other nasty}
13
+ spec.homepage = "https://github.com/drubin/carrier-services"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "mechanize", "~> 2.7.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,6 @@
1
+ require "carrier_services/version"
2
+ require "mechanize"
3
+ require "carrier_services/mtn"
4
+
5
+ module CarrierServices
6
+ end
@@ -0,0 +1,46 @@
1
+ module CarrierServices
2
+ class Mtn
3
+ BALANCE_URL="http://www.mtn.co.za/Internet/MyAccount/Pages/Balance.aspx"
4
+
5
+ def get_balance(msisdn,pin)
6
+ agent = Mechanize.new
7
+ agent.user_agent_alias = 'Mac Safari'
8
+ page = agent.get BALANCE_URL
9
+ login = page.form_with :name => "aspnetForm"
10
+ #puts login.inspect
11
+ login.field_with(:name => /UserName/).value = msisdn
12
+ login.field_with(:name => /Password/).value = pin
13
+ #Stupid aspx has javascript links, this value MIGHT change and then we need to pull it out via regex :(
14
+ login.add_field!('ctl00$ctl00$ctl09$g_22bbfcb4_42f7_422e_af7b_16e2d59216f4$ctl01$LoginView1$Login1$Login1$LoginButton', 'ctl00$Login1')
15
+
16
+
17
+ balance = login.submit
18
+ number_div = (balance.search('span').find_all { |node| node['id'] =~ /blMsisdn/}).first
19
+ balance_div = (balance.search('span').find_all { |node| node['id'] =~ /lblPurchaseLimit/}).first
20
+
21
+ #puts number_div.text
22
+ #puts balance_div.text
23
+
24
+ #puts "----"
25
+ bundle_type_div = (balance.search('span').find_all { |node| node['id'] =~ /lblBundleType/}).first
26
+ bundle_amount_div = (balance.search('span').find_all { |node| node['id'] =~ /lblBundleBalance/}).first
27
+ bundle_expire_div = (balance.search('span').find_all { |node| node['id'] =~ /lblBundleExpDate/}).first
28
+
29
+
30
+ #puts bundle_type_div.text
31
+ #puts bundle_amount_div.text
32
+ #puts bundle_expire_div.text
33
+ {
34
+ :msisdn =>number_div.text,
35
+ :airtime =>balance_div.text,
36
+ :bundles => [
37
+ {
38
+ :type=>bundle_type_div.text,
39
+ :amount=>bundle_amount_div.text,
40
+ :expires=>bundle_expire_div.text
41
+ }
42
+ ]
43
+ }
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module CarrierServices
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe CarrierServices do
4
+ it 'should return correct version string' do
5
+ CarrierServices::VERSION == "0.0.1"
6
+ end
7
+ end
data/spec/mtn_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe CarrierServices::Mtn do
4
+ it 'Should log you in' do
5
+ msisdn = ENV['MSISDN']
6
+ pin = ENV['PIN']
7
+ balance = CarrierServices::Mtn.new().get_balance(msisdn, pin)
8
+ puts balance.inspect
9
+
10
+ #Stupid login form takes in number in 071 format but returns it in 2771
11
+ balance[:msisdn].should == msisdn.to_s.gsub(/^0/,'27')
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'carrier-services'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.formatter = 'documentation'
7
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrier-services
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Rubin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.7.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Allows you to interact with your carrier via ruby. Often handling the
79
+ page scraping an all the other nasty
80
+ email:
81
+ - davidrub@gmail.com.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - carrier-services.gemspec
92
+ - lib/carrier-services.rb
93
+ - lib/carrier_services/mtn.rb
94
+ - lib/carrier_services/version.rb
95
+ - spec/carrier_services_spec.rb
96
+ - spec/mtn_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: https://github.com/drubin/carrier-services
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: 2833771281688881686
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ segments:
121
+ - 0
122
+ hash: 2833771281688881686
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.23
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Allows you to interact with your carrier via ruby.Often handling the page
129
+ scraping an all the other nasty
130
+ test_files:
131
+ - spec/carrier_services_spec.rb
132
+ - spec/mtn_spec.rb
133
+ - spec/spec_helper.rb