mediaburst 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -0
- data/lib/mediaburst/api.rb +25 -2
- data/lib/mediaburst/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -52,6 +52,18 @@ Check the response for errors:
|
|
52
52
|
|
53
53
|
On error, the value of the key referenced by the number will equal the [error code][5] returned from Mediaburst.
|
54
54
|
|
55
|
+
### Checking the Account's Credit
|
56
|
+
|
57
|
+
Create an instance of the Mediaburst client:
|
58
|
+
|
59
|
+
client = Mediaburst::API.new('username', 'password')
|
60
|
+
|
61
|
+
Request the credit amount
|
62
|
+
|
63
|
+
client.get_credit
|
64
|
+
=> "150"
|
65
|
+
|
66
|
+
Given invalid credentials, this method will return nil. If the server responds with anything other than a 200, a Mediaburst::ServerError exception is raised.
|
55
67
|
|
56
68
|
## Development
|
57
69
|
|
data/lib/mediaburst/api.rb
CHANGED
@@ -2,7 +2,8 @@ require 'nokogiri'
|
|
2
2
|
require 'net/http'
|
3
3
|
|
4
4
|
module Mediaburst
|
5
|
-
|
5
|
+
SEND_ENDPOINT = 'http://sms.message-platform.com/xml/send.aspx'
|
6
|
+
CREDIT_ENDPOINT = 'http://sms.message-platform.com/http/credit.aspx'
|
6
7
|
|
7
8
|
# Thrown when an invalid request is made,
|
8
9
|
# e.g invalid credentials were used
|
@@ -18,6 +19,28 @@ module Mediaburst
|
|
18
19
|
def initialize(u, p)
|
19
20
|
@auth = {:username => u, :password => p}
|
20
21
|
end
|
22
|
+
|
23
|
+
|
24
|
+
# Returns the about of credit left on a user account
|
25
|
+
#
|
26
|
+
# nil if there was a problem retrieving the value, and
|
27
|
+
# Throws an exception if the server didn't process
|
28
|
+
# the request succesfully.
|
29
|
+
def get_credit
|
30
|
+
uri = URI.parse(CREDIT_ENDPOINT + "?username=#{@auth[:username]}&password=#{@auth[:password]}")
|
31
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
33
|
+
request["Content-Type"] = "text/html"
|
34
|
+
|
35
|
+
response = http.request(request)
|
36
|
+
|
37
|
+
case response
|
38
|
+
when Net::HTTPSuccess
|
39
|
+
return response.body.gsub!(/^Current Credit: ([0-9]+)/, '\1')
|
40
|
+
else
|
41
|
+
raise Mediaburst::ServerError, "Request failed: #{response}"
|
42
|
+
end
|
43
|
+
end
|
21
44
|
|
22
45
|
# Takes a number or array of numbers and a content string
|
23
46
|
# and sends to the mediaburst SMS API endpoint.
|
@@ -59,7 +82,7 @@ module Mediaburst
|
|
59
82
|
# Send a request to the endpoint
|
60
83
|
def send_request(request_body)
|
61
84
|
# Create and send the request
|
62
|
-
uri = URI.parse(
|
85
|
+
uri = URI.parse(SEND_ENDPOINT)
|
63
86
|
http = Net::HTTP.new(uri.host, uri.port)
|
64
87
|
request = Net::HTTP::Post.new(uri.request_uri)
|
65
88
|
request.body = request_body
|
data/lib/mediaburst/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mediaburst
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Hall
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-10 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|