clockworksms 1.0.0 → 1.1.0

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/README.md CHANGED
@@ -77,12 +77,12 @@ You should not use the `Clockwork::Message#deliver` method for each message, but
77
77
  end
78
78
  end
79
79
 
80
- ### Check credit
80
+ ### Check balance
81
81
 
82
82
  require 'clockwork'
83
83
  api = Clockwork::API.new( 'API_KEY_GOES_HERE' )
84
- remaining_messages = Clockwork::API.credit
85
- puts remaining messages # => 240
84
+ balance = Clockwork::API.balance
85
+ puts balance # => { :account_type => "PAYG", :balance => 575.23, :currency => { :code => "GBP", :symbol => "£" } }
86
86
 
87
87
  ## License
88
88
 
@@ -103,11 +103,9 @@ and submit a pull request. Please add RSpec tests for your use case.
103
103
 
104
104
  First, create a file at spec/spec_authentication_details containing the following:
105
105
 
106
- 34023ada3ec0d99213f91a12a2329ba932665ed7
107
- MyLegacyAPIUsername@mydomain.com
108
- MyPassword
106
+ YOUR_API_KEY_HERE
109
107
 
110
- Substitute your own API key, username and password on lines 1, 2, and 3 of the file.
108
+ Substitute your own API key on line 1 of the file and replace the telephone numbers in the spec files with your own.
111
109
 
112
110
  Then, run `rspec`.
113
111
 
@@ -116,4 +114,14 @@ Then, run `rspec`.
116
114
  [3]: http://www.github.com/mediaburst/clockwork-ruby
117
115
  [4]: http://rubydoc.info/github/mediaburst/clockwork-ruby/master/Clockwork/API
118
116
  [5]: http://rubydoc.info/github/mediaburst/clockwork-ruby/master/Clockwork/SMS
119
- [6]: http://rubydoc.info/github/mediaburst/clockwork-ruby/master/Clockwork/SMS/Response
117
+ [6]: http://rubydoc.info/github/mediaburst/clockwork-ruby/master/Clockwork/SMS/Response
118
+
119
+ ## Changelog
120
+
121
+ ### 1.0.0 (18th July, 2012)
122
+
123
+ * Initial release of wrapper [JI]
124
+
125
+ ### 1.1.0 (10th September, 2012)
126
+
127
+ * API#credit is now deprecated: use API#balance instead.
@@ -2,7 +2,7 @@
2
2
  module Clockwork
3
3
 
4
4
  # Current API wrapper version
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
 
7
7
  # @author James Inman <james@mediaburst.co.uk>
8
8
  # You must create an instance of Clockwork::API to begin using the API.
@@ -11,7 +11,9 @@ module Clockwork
11
11
  # URL of the SMS API send action
12
12
  SMS_URL = "api.clockworksms.com/xml/send"
13
13
  # URL of the SMS API check credit action
14
- CREDIT_URL = "api.clockworksms.com/xml/credit"
14
+ CREDIT_URL = "api.clockworksms.com/xml/credit"
15
+ # URL of the SMS API check balance action
16
+ BALANCE_URL = "api.clockworksms.com/xml/balance"
15
17
 
16
18
  # API key provided in Clockwork::API#initialize.
17
19
  # @return [string]
@@ -120,6 +122,15 @@ module Clockwork
120
122
  credit = Clockwork::XML::Credit.parse( response )
121
123
  end
122
124
 
125
+ # Check the remaining credit for this account.
126
+ # @raise Clockwork::Error::Authentication - if API login details are incorrect
127
+ # @return [integer] Number of messages remaining
128
+ def balance
129
+ xml = Clockwork::XML::Balance.build( self )
130
+ response = Clockwork::HTTP.post( Clockwork::API::BALANCE_URL, xml, @use_ssl )
131
+ balance = Clockwork::XML::Balance.parse( response )
132
+ end
133
+
123
134
  # Deliver multiple messages created using Clockwork::API#messages.build.
124
135
  # @return [array] Array of Clockwork::SMS::Response objects for messages.
125
136
  def deliver
@@ -0,0 +1,53 @@
1
+ module Clockwork
2
+ module XML
3
+
4
+ # @author James Inman <james@mediaburst.co.uk>
5
+ # XML building and parsing for checking balance.
6
+ class Balance
7
+
8
+ # Build the XML data to check the balance from the XML API.
9
+ # @param [Clockwork::API] api Instance of Clockwork::API
10
+ # @return [string] XML data
11
+ def self.build api
12
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
13
+ xml.Balance {
14
+ if api.api_key
15
+ xml.Key api.api_key
16
+ else
17
+ xml.Username api.username
18
+ xml.Password api.password
19
+ end
20
+ }
21
+ end
22
+ builder.to_xml
23
+ end
24
+
25
+ # Parse the XML response.
26
+ # @param [Net::HTTPResponse] response Instance of Net::HTTPResponse
27
+ # @raise Clockwork:HTTPError - if a connection to the Clockwork API cannot be made
28
+ # @raise Clockwork::Error::Generic - if the API returns an error code other than 2
29
+ # @raise Clockwork::Error::Authentication - if API login details are incorrect
30
+ # @return [string] Number of remaining credits
31
+ def self.parse response
32
+ if response.code.to_i == 200
33
+ doc = Nokogiri.parse( response.body )
34
+ if doc.css('ErrDesc').empty?
35
+ hsh = {}
36
+ hsh[:account_type] = doc.css('Balance_Resp').css('AccountType').inner_html
37
+ hsh[:balance] = doc.css('Balance_Resp').css('Balance').inner_html.to_f
38
+ hsh[:currency] = { :code => doc.css('Balance_Resp').css('Currency').css('Code').inner_html, :symbol => doc.css('Balance_Resp').css('Currency').css('Symbol').inner_html }
39
+ hsh
40
+ elsif doc.css('ErrNo').inner_html.to_i == 2
41
+ raise Clockwork::Error::Authentication, doc.css('ErrDesc').inner_html
42
+ else
43
+ raise Clockwork::Error::Generic, doc.css('ErrDesc').inner_html
44
+ end
45
+ else
46
+ raise Clockwork::Error::HTTP, "Could not connect to the Clockwork API to check balance."
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
metadata CHANGED
@@ -1,91 +1,92 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clockworksms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ prerelease:
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mediaburst
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
16
+ version_requirements: !ruby/object:Gem::Requirement
18
17
  requirements:
19
18
  - - ! '>='
20
19
  - !ruby/object:Gem::Version
21
20
  version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
21
  none: false
22
+ requirement: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
32
+ version_requirements: !ruby/object:Gem::Requirement
34
33
  requirements:
35
34
  - - ! '>='
36
35
  - !ruby/object:Gem::Version
37
36
  version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
37
  none: false
38
+ requirement: !ruby/object:Gem::Requirement
42
39
  requirements:
43
40
  - - ! '>='
44
41
  - !ruby/object:Gem::Version
45
42
  version: '0'
46
- description: Ruby Gem for the Clockwork API. Send text messages with the easy to use
47
- SMS API from Mediaburst.
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ description: Ruby Gem for the Clockwork API. Send text messages with the easy to use SMS API from Mediaburst.
48
47
  email: hello@mediaburst.co.uk
49
48
  executables: []
50
49
  extensions: []
51
50
  extra_rdoc_files: []
52
51
  files:
52
+ - lib/clockwork.rb
53
53
  - lib/clockwork/api.rb
54
54
  - lib/clockwork/error.rb
55
55
  - lib/clockwork/http.rb
56
56
  - lib/clockwork/message_collection.rb
57
- - lib/clockwork/sms/response.rb
58
57
  - lib/clockwork/sms.rb
58
+ - lib/clockwork/sms/response.rb
59
+ - lib/clockwork/xml/balance.rb
59
60
  - lib/clockwork/xml/credit.rb
60
61
  - lib/clockwork/xml/sms.rb
61
62
  - lib/clockwork/xml/xml.rb
62
- - lib/clockwork.rb
63
63
  - Gemfile
64
64
  - Gemfile.lock
65
65
  - LICENSE
66
66
  - README.md
67
67
  homepage: http://www.clockworksms.com/
68
68
  licenses: []
69
- post_install_message:
69
+ post_install_message:
70
70
  rdoc_options: []
71
71
  require_paths:
72
72
  - lib
73
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
74
  requirements:
76
75
  - - ! '>='
77
76
  - !ruby/object:Gem::Version
78
77
  version: '0'
79
- required_rubygems_version: !ruby/object:Gem::Requirement
80
78
  none: false
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
80
  requirements:
82
81
  - - ! '>='
83
82
  - !ruby/object:Gem::Version
84
83
  version: '0'
84
+ none: false
85
85
  requirements: []
86
- rubyforge_project:
86
+ rubyforge_project:
87
87
  rubygems_version: 1.8.24
88
- signing_key:
88
+ signing_key:
89
89
  specification_version: 3
90
90
  summary: Ruby Gem for the Clockwork API.
91
91
  test_files: []
92
+ ...