Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding check credit, dummy test details, HTTP library.
- Loading branch information
Showing
11 changed files
with
263 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,2 +1,3 @@ | |||
doc/ | doc/ | ||
.yardoc/ | .yardoc/ | ||
spec/spec_authentication_details* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
source 'https://rubygems.org' | |||
|
|||
gem 'nokogiri' | |||
gem 'faraday' | |||
|
|||
group :development do | |||
gem 'rspec' | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
GEM | |||
remote: https://rubygems.org/ | |||
specs: | |||
diff-lcs (1.1.3) | |||
faraday (0.8.0) | |||
multipart-post (~> 1.1) | |||
multipart-post (1.1.5) | |||
nokogiri (1.5.2) | |||
rspec (2.10.0) | |||
rspec-core (~> 2.10.0) | |||
rspec-expectations (~> 2.10.0) | |||
rspec-mocks (~> 2.10.0) | |||
rspec-core (2.10.0) | |||
rspec-expectations (2.10.0) | |||
diff-lcs (~> 1.1.3) | |||
rspec-mocks (2.10.1) | |||
|
|||
PLATFORMS | |||
ruby | |||
|
|||
DEPENDENCIES | |||
faraday | |||
nokogiri | |||
rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,7 +1,12 @@ | |||
lib_dir = File.expand_path(File.dirname(__FILE__)) | lib_dir = File.expand_path(File.dirname(__FILE__)) | ||
$LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir) | $LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir) | ||
|
|
||
require 'net/http' | |||
require 'nokogiri' | |||
|
|||
require 'clockwork/errors' | require 'clockwork/errors' | ||
require 'clockwork/http' | |||
require 'clockwork/xml/xml' | |||
|
|
||
require 'clockwork/api' | require 'clockwork/api' | ||
require 'clockwork/sms' | require 'clockwork/sms' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
module Clockwork | |||
|
|||
# Wrapper around NET/HTTP | |||
class HTTP | |||
|
|||
# Build a HTTP POST request. | |||
# @param [string] url URL to POST to | |||
# @param [string] data Body of the POST request. | |||
# @param [boolean] use_ssl Whether to use SSL when making the request. | |||
# @return [string] XML data | |||
def self.post url, data = '', use_ssl = true | |||
|
|||
if use_ssl | |||
uri = URI.parse "https://#{url}" | |||
req = Net::HTTP::Post.new( uri.path ) | |||
|
|||
socket = Net::HTTP.new( uri.host, uri.port ) | |||
socket.use_ssl = true | |||
socket.verify_mode = OpenSSL::SSL::VERIFY_NONE | |||
else | |||
uri = URI.parse "http://#{url}" | |||
req = Net::HTTP::Post.new( uri.path ) | |||
|
|||
socket = Net::HTTP.new( uri.host, uri.port ) | |||
socket.use_ssl = true | |||
socket.verify_mode = OpenSSL::SSL::VERIFY_NONE | |||
end | |||
|
|||
req.content_type = "text/xml" | |||
# req.initialize_http_header( 'User-Agent' => "Clockwork .NET Wrapper/#{Clockwork::VERSION}" ) | |||
req.body = data | |||
|
|||
response = socket.start do |http| | |||
http.request( req ) | |||
end | |||
|
|||
response | |||
|
|||
end | |||
|
|||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
module Clockwork | |||
module XML | |||
|
|||
# XML building and parsing for checking credit. | |||
class Credit | |||
|
|||
# Build the XML data to check the credit from the XML API. | |||
# @param [Clockwork::API] api Instance of Clockwork::API | |||
# @return [string] XML data | |||
def self.build api | |||
if api.api_key | |||
builder = Nokogiri::XML::Builder.new do |xml| | |||
xml.Credit { | |||
xml.Key api.api_key | |||
} | |||
end | |||
else | |||
builder = Nokogiri::XML::Builder.new do |xml| | |||
xml.Credit { | |||
xml.Username api.username | |||
xml.Password api.password | |||
} | |||
end | |||
end | |||
builder.to_xml | |||
end | |||
|
|||
# Parse the XML response | |||
# @param [Net::HTTPResponse] api Instance of Clockwork::API | |||
# @return [string] XML data | |||
def self.parse response | |||
if response.code.to_i == 200 | |||
doc = Nokogiri.parse( response.body ) | |||
doc.css('Credit').inner_html.to_i | |||
else | |||
raise Clockwork::HTTPError, "Could not connect to the Clockwork API to check credit." | |||
end | |||
end | |||
|
|||
end | |||
|
|||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
require 'nokogiri' | |||
|
|||
module Clockwork | |||
|
|||
# Wrapper for the XML builder/parser | |||
module XML | |||
end | |||
|
|||
end | |||
|
|||
# Require everything in this directory | |||
dir_path = File.dirname(__FILE__) | |||
Dir["#{dir_path}/*.rb"].each do |file| | |||
next if file =~ /xml.rb$/ | |||
require file | |||
end |
Oops, something went wrong.