sendhub 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -28,31 +28,43 @@ h2. Rails 2.x Example
28
28
 
29
29
  config/enviroment.rb
30
30
 
31
- <pre><code>config.gem 'sendhub'
32
- require 'sendhub'
31
+ <pre><code>Rails::Initializer.run do |config|
32
+ ...
33
+ config.gem 'sendhub'
34
+ require 'sendhub'
35
+ ...
36
+ end
33
37
  </code></pre>
34
38
 
35
39
  config/enviroments/production.rb
36
40
 
37
- <pre><code>config.action_mailer.delivery_method = :sendhub
41
+ <pre><code>...
42
+ config.action_mailer.delivery_method = :sendhub
38
43
  config.action_mailer.sendhub_settings = {
39
44
  :api_key => "YOUR_API_KEY",
40
45
  :secret_key => "YOUR_SECRET_KEY"
41
46
  }
47
+ ...
42
48
  </code></pre>
43
49
 
44
50
  h2. Rails 3.x Example
45
51
 
46
- config/enviroment.rb
52
+ Gemfile
47
53
 
48
- <pre><code>config.gem 'sendhub'
54
+ <pre><code>...
55
+ gem 'sendhub'
56
+ ...
49
57
  </code></pre>
50
58
 
51
59
  config/enviroments/production.rb
52
60
 
53
- <pre><code>config.action_mailer.delivery_method = :sendhub
54
- config.action_mailer.sendhub_settings = {
55
- :api_key => "YOUR_API_KEY",
56
- :secret_key => "YOUR_SECRET_KEY"
57
- }
61
+ <pre><code>YOUR_APP::Application.configure do
62
+ ...
63
+ config.action_mailer.delivery_method = :sendhub
64
+ config.action_mailer.sendhub_settings = {
65
+ :api_key => "YOUR_API_KEY",
66
+ :secret_key => "YOUR_SECRET_KEY"
67
+ }
68
+ ...
69
+ end
58
70
  </code></pre>
@@ -1,11 +1,12 @@
1
1
  module Sendhub
2
2
  class Client
3
3
 
4
- VERSION = '0.1.10'
4
+ VERSION = '0.1.11'
5
5
 
6
6
  def initialize(config=nil)
7
7
  config[:host] ||= 'api.sendhub.net'
8
- @uri = URI.parse('http://'+config[:host]+'/')
8
+ config[:protocol] ||= 'https'
9
+ @uri = URI.parse(config[:protocol]+'://'+config[:host]+'/')
9
10
 
10
11
  @api_key = config[:api_key]
11
12
  @secret_key = config[:secret_key]
@@ -15,13 +16,12 @@ module Sendhub
15
16
 
16
17
  def send_email(options={})
17
18
  res = _post '/emails', nil, options
18
- #res.merge!('redirect_url' => @uri.to_s+"merchants/#{@merchant_id}/transactions/#{res['id']}")
19
- #res.merge!('secret_token' => securely_hash_data("#{res['id']}-#{res['amount']}"))
20
19
  Sendhub::Response.new(res)
21
20
  end
22
21
 
23
- def get(options={})
24
- res = _get('/email/' + options[:email_id])
22
+ def get_email(options={})
23
+ email_id = options.delete(:id)
24
+ res = _get('/emails/' + email_id, options)
25
25
  Sendhub::Response.new(res)
26
26
  end
27
27
 
data/lib/sendhub/http.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Sendhub
2
2
  class Client
3
3
  private
4
- def _get(path)
5
- http(Net::HTTP::Get, path)
4
+ def _get(path, options={})
5
+ http(Net::HTTP::Get, path, nil, options)
6
6
  end
7
7
 
8
8
  def _post(path, body = nil, options={})
@@ -20,19 +20,24 @@ module Sendhub
20
20
  options.merge!(:unique => Time.now.utc.to_i)
21
21
  options.merge!(:secret => securely_hash_data(options[:unique]))
22
22
 
23
- #if ssl?
24
- #connection.use_ssl = true
25
- #connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
23
+ if @uri.scheme == 'https'
24
+ connection.use_ssl = true
25
+ connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
26
26
  #connection.ca_file = Configuration.ca_file
27
27
  #connection.verify_callback = proc { |preverify_ok, ssl_context| verify_ssl_certificate(preverify_ok, ssl_context) }
28
- #end
28
+ end
29
29
  connection.start do |http|
30
- request = http_method.new("/v1#{path}")
30
+ if http_method.inspect == 'Net::HTTP::Get' and !options.empty?
31
+ puts options.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join("&")
32
+ request = http_method.new("/v1#{path}" + "?" + (options.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }).join("&"))
33
+ else
34
+ request = http_method.new("/v1#{path}")
35
+ end
31
36
  request["Accept"] = "application/xml"
32
37
  request["User-Agent"] = 'SendhubRubyClient/'+Sendhub::Client::VERSION
33
38
  request["Accept-Encoding"] = "gzip"
34
39
  request["X-ApiVersion"] = Sendhub::Client::VERSION
35
- request.basic_auth @api_key, @secret_key
40
+ # request.basic_auth @api_key, @secret_key
36
41
  if body
37
42
  request["Content-Type"] = "application/xml"
38
43
  request.body = body
@@ -41,6 +46,7 @@ module Sendhub
41
46
  request.set_form_data(options)
42
47
  end
43
48
  response = http.request(request)
49
+ puts response.body
44
50
  return JSON.parse(response.body)
45
51
  end
46
52
 
@@ -8,6 +8,7 @@ module Sendhub
8
8
  end
9
9
 
10
10
  def deliver!(message)
11
+
11
12
  res = @client.send_email(
12
13
  :from => message.from,
13
14
  :to => message.to,
@@ -15,6 +16,8 @@ module Sendhub
15
16
  :body => message.body,
16
17
  :content_type => message.content_type
17
18
  )
19
+
20
+ puts res.inspect
18
21
  end
19
22
  end
20
23
  end
data/lib/sendhub.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'uri'
2
2
  require 'net/http'
3
+ require 'net/https'
3
4
  require 'digest/sha1'
5
+ require 'cgi'
4
6
 
5
7
  require 'rubygems'
6
8
  require 'json'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendhub
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 10
10
- version: 0.1.10
9
+ - 11
10
+ version: 0.1.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Taylor
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-07 00:00:00 +01:00
18
+ date: 2010-11-10 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency