sendhub 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Richard Taylor
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1 @@
1
+ h2. The Ruby Client library for SendHub.net
data/lib/sendhub.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'digest/sha1'
4
+
5
+ require 'rubygems'
6
+ require 'json'
7
+
8
+ module Sendhub
9
+ end
10
+
11
+ require 'sendhub/rails'
12
+ require 'sendhub/http'
13
+ require 'sendhub/response'
14
+ require 'sendhub/client'
@@ -0,0 +1,29 @@
1
+ module Sendhub
2
+ class Client
3
+
4
+ VERSION = '0.1.0'
5
+
6
+ def initialize(config=nil)
7
+ config[:host] ||= 'api.sendhub.net'
8
+ @uri = URI.parse('http://'+config[:host]+'/')
9
+
10
+ @api_key = config[:api_key]
11
+ @secret_key = config[:secret_key]
12
+
13
+ puts "SendhubRubyClient: #{@uri}, #{@api_key}"
14
+ end
15
+
16
+ def send_email(options={})
17
+ 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
+ Sendhub::Response.new(res)
21
+ end
22
+
23
+ def get(options={})
24
+ res = _get('/email/' + options[:email_id])
25
+ Sendhub::Response.new(res)
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,60 @@
1
+ module Sendhub
2
+ class Client
3
+ private
4
+ def _get(path)
5
+ http(Net::HTTP::Get, path)
6
+ end
7
+
8
+ def _post(path, body = nil, options={})
9
+ http(Net::HTTP::Post, path, body, options)
10
+ end
11
+
12
+ def securely_hash_data(data)
13
+ Digest::SHA1.hexdigest("--#{@api_key}-#{@secret_key}-#{data}--")
14
+ end
15
+
16
+ def http(http_method, path, body = nil, options={})
17
+ connection = Net::HTTP.new(@uri.host, @uri.port)
18
+
19
+ options.merge!(:api_key => @api_key)
20
+ options.merge!(:unique => Time.now.utc.to_i)
21
+ options.merge!(:secret => securely_hash_data(options[:unique]))
22
+
23
+ puts "Path: #{path}"
24
+
25
+ #if ssl?
26
+ #connection.use_ssl = true
27
+ #connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
28
+ #connection.ca_file = Configuration.ca_file
29
+ #connection.verify_callback = proc { |preverify_ok, ssl_context| verify_ssl_certificate(preverify_ok, ssl_context) }
30
+ #end
31
+ connection.start do |http|
32
+ request = http_method.new("/v1#{path}")
33
+ request["Accept"] = "application/xml"
34
+ request["User-Agent"] = 'SendhubRubyClient/'+Sendhub::Client::VERSION
35
+ request["Accept-Encoding"] = "gzip"
36
+ request["X-ApiVersion"] = Sendhub::Client::VERSION
37
+ request.basic_auth @api_key, @secret_key
38
+ if body
39
+ request["Content-Type"] = "application/xml"
40
+ request.body = body
41
+ end
42
+ if http_method.inspect == 'Net::HTTP::Post' and !options.empty?
43
+ request.set_form_data(options)
44
+ end
45
+ response = http.request(request)
46
+ return JSON.parse(response.body)
47
+ end
48
+
49
+ end
50
+
51
+ #def verify_ssl_certificate(preverify_ok, ssl_context)
52
+ # if preverify_ok != true || ssl_context.error != 0
53
+ # err_msg = "SSL Verification failed -- Preverify: #{preverify_ok}, Error: #{ssl_context.error_string} (#{ssl_context.error})"
54
+ # Configuration.logger.error err_msg
55
+ # raise err_msg
56
+ # end
57
+ # true
58
+ #end
59
+ end
60
+ end
@@ -0,0 +1,35 @@
1
+ require 'action_mailer'
2
+
3
+ module SendhubMethods
4
+ def perform_delivery_sendhub(message)
5
+ #Sendhub.send_through_sendhub(message)
6
+ end
7
+
8
+ def tag(value)
9
+ @tag = value
10
+ end
11
+
12
+ def self.included(base)
13
+ base.extend(ClassMethods)
14
+ base.class_eval do
15
+ alias_method_chain :create_mail, :tag
16
+ end
17
+ end
18
+
19
+ def create_mail_with_tag
20
+ returning create_mail_without_tag do |mail|
21
+ mail.tag = @tag if @tag
22
+ end
23
+ end
24
+
25
+ module ClassMethods
26
+ def sendhub_api_key=(value)
27
+ #Sendhub.api_key = value
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ class ActionMailer::Base
34
+ include SendhubMethods
35
+ end
@@ -0,0 +1,12 @@
1
+ module Sendhub
2
+ class Response
3
+ attr_accessor :id, :status, :from, :to, :error
4
+ def initialize(params={})
5
+ @id = params['id']
6
+ @status = params['status']
7
+ @from = params['from']
8
+ @to = params['to']
9
+ @error = params['error']
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendhub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-08-09 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: sendhub is a Ruby client library for SendHub.net.
17
+ email: moomerman@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - LICENSE
26
+ - README.textile
27
+ - lib/sendhub.rb
28
+ - lib/sendhub/client.rb
29
+ - lib/sendhub/http.rb
30
+ - lib/sendhub/rails.rb
31
+ - lib/sendhub/response.rb
32
+ has_rdoc: true
33
+ homepage: http://sendhub.net/
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --inline-source
39
+ - --charset=UTF-8
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project: sendhub
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: sendhub is a Ruby client library for SendHub.net.
61
+ test_files: []
62
+