sendgrid_api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +43 -0
- data/lib/sendgrid/client.rb +16 -0
- data/lib/sendgrid/response.rb +22 -0
- data/lib/sendgrid/subuser.rb +76 -0
- data/lib/sendgrid/version.rb +3 -0
- data/lib/sendgrid.rb +12 -0
- metadata +69 -0
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rake/gempackagetask"
|
2
|
+
require "spec/rake/spectask"
|
3
|
+
require "bundler"
|
4
|
+
|
5
|
+
require "lib/sendgrid/version"
|
6
|
+
|
7
|
+
desc "Default: run specs"
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
desc "Run specs"
|
11
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
12
|
+
t.libs << "lib" << "spec"
|
13
|
+
t.spec_opts << "-c -D"
|
14
|
+
t.pattern = "spec/**/*_spec.rb"
|
15
|
+
t.rcov = ENV["RCOV"] == "true"
|
16
|
+
t.rcov_opts << "--text-summary"
|
17
|
+
t.rcov_opts << "--sort" << "coverage" << "--sort-reverse"
|
18
|
+
t.rcov_opts << "--exclude features/,spec/"
|
19
|
+
end
|
20
|
+
|
21
|
+
@spec = Gem::Specification.new do |s|
|
22
|
+
s.name = "sendgrid_api"
|
23
|
+
s.version = Sendgrid::VERSION
|
24
|
+
s.platform = Gem::Platform::RUBY
|
25
|
+
s.has_rdoc = false
|
26
|
+
s.summary = "Talk to sendgrid.com"
|
27
|
+
s.description = s.summary
|
28
|
+
s.authors = ["ninja@engineyard.com"]
|
29
|
+
s.email = "ninja@engineyard.com"
|
30
|
+
s.homepage = "http://github.com/engineyard/sendgrid_api"
|
31
|
+
|
32
|
+
s.require_path = "lib"
|
33
|
+
s.files = %w(Rakefile) + Dir.glob("lib/**/*.rb")
|
34
|
+
manifest = Bundler::Environment.load("Gemfile")
|
35
|
+
manifest.dependencies.each do |dep|
|
36
|
+
next if dep.only && dep.only.include?("test")
|
37
|
+
s.add_dependency(dep.name, dep.version)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::GemPackageTask.new(@spec) do |pkg|
|
42
|
+
pkg.gem_spec = @spec
|
43
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Sendgrid
|
2
|
+
class Client
|
3
|
+
def initialize(api_user, api_key)
|
4
|
+
@api_user = api_user
|
5
|
+
@api_key = api_key
|
6
|
+
end
|
7
|
+
|
8
|
+
def request(path, params={})
|
9
|
+
uri = URI.join("http://sendgrid.com/api/", "#{path}.json")
|
10
|
+
post_params = {"api_user" => @api_user,
|
11
|
+
"api_key" => @api_key}.merge(params)
|
12
|
+
response = Net::HTTP.post_form(uri, post_params)
|
13
|
+
Sendgrid::Response.new(response)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Sendgrid
|
2
|
+
class Response
|
3
|
+
def initialize(response)
|
4
|
+
@response = response
|
5
|
+
end
|
6
|
+
|
7
|
+
def errors?
|
8
|
+
return false if Array === body
|
9
|
+
return true if body.key?("error")
|
10
|
+
return false unless body.key?("message")
|
11
|
+
["error", "User not found"].include?(body["message"])
|
12
|
+
end
|
13
|
+
|
14
|
+
def successful?
|
15
|
+
! errors?
|
16
|
+
end
|
17
|
+
|
18
|
+
def body
|
19
|
+
JSON.parse(@response.body)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Sendgrid
|
2
|
+
class Subuser
|
3
|
+
def self.defaults
|
4
|
+
{
|
5
|
+
:username => "", :email => "",
|
6
|
+
:first_name => "", :last_name => "",
|
7
|
+
:website => "",
|
8
|
+
:phone => "Unknown",
|
9
|
+
:address => "Unknown",
|
10
|
+
:city => "Unknown",
|
11
|
+
:state => "Unknown",
|
12
|
+
:country => "Unknown",
|
13
|
+
:zip => "Unknown"
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create(attributes)
|
18
|
+
response = client.request("user.add", defaults.merge(attributes))
|
19
|
+
if response.errors?
|
20
|
+
new(response.body)
|
21
|
+
else
|
22
|
+
get(attributes[:email])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.search(attributes={})
|
27
|
+
response = client.request("user.profile", attributes.merge!("task" => "get"))
|
28
|
+
return [] if response.errors?
|
29
|
+
response.body.collect { |subuser| new(subuser) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.all
|
33
|
+
search
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get(email)
|
37
|
+
return nil unless email
|
38
|
+
return nil if (subusers = search("email" => email)).empty?
|
39
|
+
subusers.first
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.client
|
43
|
+
@client ||= Client.new(Sendgrid.api_user, Sendgrid.api_key)
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_reader :first_name, :last_name, :email, :activated, :errors
|
47
|
+
|
48
|
+
def initialize(response={})
|
49
|
+
@first_name = response["first_name"]
|
50
|
+
@last_name = response["last_name"]
|
51
|
+
@email = response["email"]
|
52
|
+
@activated = response["active"] == "true"
|
53
|
+
@errors = response["errors"] || []
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_method :activated?, :activated
|
57
|
+
|
58
|
+
def deactivate
|
59
|
+
client.request("user.disable", {"user" => email}).successful?
|
60
|
+
end
|
61
|
+
|
62
|
+
def activate
|
63
|
+
client.request("user.enable", {"user" => email}).successful?
|
64
|
+
end
|
65
|
+
|
66
|
+
def statistics
|
67
|
+
response = client.request("user.stats", {"user" => email})
|
68
|
+
response.errors? ? [] : response.body
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def client
|
73
|
+
self.class.client
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/sendgrid.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sendgrid_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ninja@engineyard.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-17 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Talk to sendgrid.com
|
26
|
+
email: ninja@engineyard.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- Rakefile
|
35
|
+
- lib/sendgrid.rb
|
36
|
+
- lib/sendgrid/subuser.rb
|
37
|
+
- lib/sendgrid/version.rb
|
38
|
+
- lib/sendgrid/response.rb
|
39
|
+
- lib/sendgrid/client.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/engineyard/sendgrid_api
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Talk to sendgrid.com
|
68
|
+
test_files: []
|
69
|
+
|