Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

Commit

Permalink
using https by default, bumped to version 0.1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
moomerman committed Nov 10, 2010
1 parent bfc39bb commit b6ac276
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/sendhub.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'uri'
require 'net/http'
require 'net/https'
require 'digest/sha1'
require 'cgi'

require 'rubygems'
require 'json'
Expand Down
12 changes: 6 additions & 6 deletions lib/sendhub/client.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module Sendhub
class Client

VERSION = '0.1.10'
VERSION = '0.1.11'

def initialize(config=nil)
config[:host] ||= 'api.sendhub.net'
@uri = URI.parse('http://'+config[:host]+'/')
config[:protocol] ||= 'https'
@uri = URI.parse(config[:protocol]+'://'+config[:host]+'/')

@api_key = config[:api_key]
@secret_key = config[:secret_key]
Expand All @@ -15,13 +16,12 @@ def initialize(config=nil)

def send_email(options={})
res = _post '/emails', nil, options
#res.merge!('redirect_url' => @uri.to_s+"merchants/#{@merchant_id}/transactions/#{res['id']}")
#res.merge!('secret_token' => securely_hash_data("#{res['id']}-#{res['amount']}"))
Sendhub::Response.new(res)
end

def get(options={})
res = _get('/email/' + options[:email_id])
def get_email(options={})
email_id = options.delete(:id)
res = _get('/emails/' + email_id, options)
Sendhub::Response.new(res)
end

Expand Down
22 changes: 14 additions & 8 deletions lib/sendhub/http.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Sendhub
class Client
private
def _get(path)
http(Net::HTTP::Get, path)
def _get(path, options={})
http(Net::HTTP::Get, path, nil, options)
end

def _post(path, body = nil, options={})
Expand All @@ -20,19 +20,24 @@ def http(http_method, path, body = nil, options={})
options.merge!(:unique => Time.now.utc.to_i)
options.merge!(:secret => securely_hash_data(options[:unique]))

#if ssl?
#connection.use_ssl = true
#connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
if @uri.scheme == 'https'
connection.use_ssl = true
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
#connection.ca_file = Configuration.ca_file
#connection.verify_callback = proc { |preverify_ok, ssl_context| verify_ssl_certificate(preverify_ok, ssl_context) }
#end
end
connection.start do |http|
request = http_method.new("/v1#{path}")
if http_method.inspect == 'Net::HTTP::Get' and !options.empty?
puts options.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join("&")
request = http_method.new("/v1#{path}" + "?" + (options.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }).join("&"))
else
request = http_method.new("/v1#{path}")
end
request["Accept"] = "application/xml"
request["User-Agent"] = 'SendhubRubyClient/'+Sendhub::Client::VERSION
request["Accept-Encoding"] = "gzip"
request["X-ApiVersion"] = Sendhub::Client::VERSION
request.basic_auth @api_key, @secret_key
# request.basic_auth @api_key, @secret_key
if body
request["Content-Type"] = "application/xml"
request.body = body
Expand All @@ -41,6 +46,7 @@ def http(http_method, path, body = nil, options={})
request.set_form_data(options)
end
response = http.request(request)
puts response.body
return JSON.parse(response.body)
end

Expand Down
3 changes: 3 additions & 0 deletions lib/sendhub/plugins/rails3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ def initialize(options)
end

def deliver!(message)

res = @client.send_email(
:from => message.from,
:to => message.to,
:subject => message.subject,
:body => message.body,
:content_type => message.content_type
)

puts res.inspect
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions sendhub.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Gem::Specification.new do |s|
s.name = %q{sendhub}
s.version = "0.1.10"
s.version = "0.1.11"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Richard Taylor"]
s.date = %q{2010-09-07}
s.date = %q{2010-11-10}
s.description = %q{sendhub is a Ruby client library for SendHub.net.}
s.email = %q{[email protected]}
s.files = ["LICENSE", "README.textile","lib/sendhub.rb"] + Dir.glob('lib/sendhub/*.rb') + Dir.glob('lib/sendhub/plugins/*.rb')
Expand Down

0 comments on commit b6ac276

Please sign in to comment.