gmail-api-ruby 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/CHANGELOG.md +4 -0
- data/README.md +8 -3
- data/gmail.gemspec +5 -4
- data/lib/gmail.rb +1 -1
- data/lib/gmail/draft.rb +7 -7
- data/lib/gmail/gmail_object.rb +2 -2
- data/lib/gmail/label.rb +10 -10
- data/lib/gmail/message.rb +9 -9
- data/lib/gmail/thread.rb +6 -6
- data/lib/gmail/version.rb +1 -1
- data/test/gmail/gmail_object_test.rb +4 -10
- data/test/gmail/util_test.rb +3 -3
- data/test/test_data.rb +2 -82
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd910aaa7588db1a4e5c11e8987373c7a5ec105
|
4
|
+
data.tar.gz: d0bff8547f5c158b11b27bdc1b8850b3a9b6ab41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02b011d121cf6f8479f526ea45df0d89d2b04487eb0fdb0e20e9f22d2fabbc3cf78d5f5eea716caea16035958b4a588951f4074ae95dcde7485cb5e49b891093
|
7
|
+
data.tar.gz: 1d4a289c6f538b19426b5baa5bd7682ab34e00cd96621236351673bf93de7621f4076dde1b4b5e6db9e4b6b17b59fd0d7322430da458aaf96f58522550138fca
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# Gmail for Ruby
|
2
2
|
|
3
|
-
A
|
3
|
+
A Ruby interface to Gmail API: Search,
|
4
4
|
read and send multipart emails, archive, mark as read/unread, delete emails,
|
5
|
-
and manage labels. Everything goes through Gmail API (and not
|
5
|
+
and manage labels. Everything goes through Gmail API (and not through IMAP or SMTP protocols)
|
6
|
+
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/gmail-api-ruby.svg)](http://badge.fury.io/rb/gmail-api-ruby)
|
8
|
+
[![Build Status](https://travis-ci.org/jhk753/gmail-ruby-api.svg)](https://travis-ci.org/jhk753/gmail-ruby-api)
|
9
|
+
[![Dependency Status](https://gemnasium.com/jhk753/gmail-ruby-api.svg)](https://gemnasium.com/jhk753/gmail-ruby-api)
|
10
|
+
|
6
11
|
|
7
12
|
# Notice
|
8
13
|
|
data/gmail.gemspec
CHANGED
@@ -16,17 +16,18 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.homepage = "http://github.com/jhk753/gmail-ruby-api"
|
17
17
|
|
18
18
|
# runtime dependencies
|
19
|
+
s.required_ruby_version = '>= 1.9.3'
|
19
20
|
s.add_dependency "mime", ">= 0.1"
|
20
21
|
s.add_dependency "mail", ">= 2.2.1"
|
21
22
|
s.add_dependency 'google-api-client'
|
22
|
-
s.add_dependency "hooks"
|
23
|
-
s.add_dependency "hashie"
|
23
|
+
s.add_dependency "hooks", ">=0.4.0"
|
24
|
+
s.add_dependency "hashie", ">=3.3.2"
|
24
25
|
|
25
26
|
# development dependencies
|
26
27
|
s.add_development_dependency "rake"
|
27
28
|
s.add_development_dependency "test-unit"
|
28
|
-
s.add_development_dependency('mocha', '~> 0.
|
29
|
-
s.add_development_dependency('shoulda', '~> 3.
|
29
|
+
s.add_development_dependency('mocha', '~> 1.0.0')
|
30
|
+
s.add_development_dependency('shoulda', '~> 3.5.0')
|
30
31
|
s.add_development_dependency "gem-release"
|
31
32
|
|
32
33
|
s.files = `git ls-files`.split("\n")
|
data/lib/gmail.rb
CHANGED
data/lib/gmail/draft.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Gmail
|
2
2
|
class Draft < APIResource
|
3
|
-
include
|
4
|
-
include
|
5
|
-
include
|
6
|
-
include
|
7
|
-
include
|
3
|
+
include Base::List
|
4
|
+
include Base::Create
|
5
|
+
include Base::Delete
|
6
|
+
include Base::Get
|
7
|
+
include Base::Update
|
8
8
|
|
9
9
|
def message
|
10
|
-
if @values.message.is_a?(
|
10
|
+
if @values.message.is_a?(Message)
|
11
11
|
@values.message
|
12
12
|
else
|
13
13
|
@values.message = Util.convert_to_gmail_object(to_hash[:message], key="message")
|
@@ -45,7 +45,7 @@ module Gmail
|
|
45
45
|
|
46
46
|
def deliver
|
47
47
|
response = Gmail.request(self.class.base_method.to_h['gmail.users.drafts.send'],{},{id: id})
|
48
|
-
|
48
|
+
Message.get(response[:id])
|
49
49
|
end
|
50
50
|
|
51
51
|
|
data/lib/gmail/gmail_object.rb
CHANGED
@@ -40,7 +40,7 @@ module Gmail
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def detailed
|
43
|
-
if self.class ==
|
43
|
+
if self.class == GmailObject
|
44
44
|
raise "Can't detail a generic GmailObject. It needs to be a Thread, Message, Draft or Label"
|
45
45
|
end
|
46
46
|
|
@@ -48,7 +48,7 @@ module Gmail
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def refresh
|
51
|
-
if self.class ==
|
51
|
+
if self.class == GmailObject
|
52
52
|
raise "Can't refresh a generic GmailObject. It needs to be a Thread, Message, Draft or Label"
|
53
53
|
end
|
54
54
|
@values = self.class.get(id).values
|
data/lib/gmail/label.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Gmail
|
2
2
|
class Label < APIResource
|
3
|
-
include
|
4
|
-
include
|
5
|
-
include
|
6
|
-
include
|
7
|
-
include
|
3
|
+
include Base::List
|
4
|
+
include Base::Create
|
5
|
+
include Base::Delete
|
6
|
+
include Base::Get
|
7
|
+
include Base::Update
|
8
8
|
|
9
9
|
def save
|
10
10
|
update(to_hash)
|
@@ -20,32 +20,32 @@ module Gmail
|
|
20
20
|
|
21
21
|
boxes.each do |method|
|
22
22
|
define_singleton_method method do
|
23
|
-
|
23
|
+
Label.get(method.to_s.upcase)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def messages filters={}
|
28
28
|
filters = {labelIds: [id]}.merge(filters)
|
29
29
|
filters[:labelIds] = filters[:labelIds] | [id]
|
30
|
-
|
30
|
+
Message.all(filters)
|
31
31
|
end
|
32
32
|
|
33
33
|
def unread_messages
|
34
34
|
if messagesUnread == 0
|
35
35
|
[]
|
36
36
|
else
|
37
|
-
|
37
|
+
Message.all({labelIds: [id, "UNREAD"]})
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def threads filters={}
|
42
42
|
filters = {labelIds: [id]}.merge(filters)
|
43
43
|
filters[:labelIds] = filters[:labelIds] | [id]
|
44
|
-
|
44
|
+
Thread.all(filters)
|
45
45
|
end
|
46
46
|
|
47
47
|
def unread_threads
|
48
|
-
|
48
|
+
Thread.all({labelIds: [id, "UNREAD"]})
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
data/lib/gmail/message.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Gmail
|
3
3
|
class Message < APIResource
|
4
|
-
include
|
5
|
-
include
|
6
|
-
include
|
7
|
-
include
|
8
|
-
include
|
4
|
+
include Base::List
|
5
|
+
include Base::Delete
|
6
|
+
include Base::Get
|
7
|
+
include Base::Modify
|
8
|
+
include Base::Trash
|
9
9
|
|
10
10
|
after_initialize :set_basics
|
11
11
|
|
12
12
|
def thread
|
13
|
-
|
13
|
+
Thread.get(threadId)
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_draft
|
17
|
-
|
17
|
+
Draft.create(message: msg_parameters)
|
18
18
|
end
|
19
19
|
|
20
20
|
def deliver!
|
21
21
|
response = Gmail.request(self.class.base_method.to_h['gmail.users.messages.send'],{}, msg_parameters)
|
22
|
-
@values =
|
22
|
+
@values = Message.get(response[:id]).values
|
23
23
|
self
|
24
24
|
end
|
25
25
|
|
26
26
|
def deliver
|
27
27
|
response = Gmail.request(self.class.base_method.to_h['gmail.users.messages.send'],{}, msg_parameters)
|
28
|
-
|
28
|
+
Message.get(response[:id])
|
29
29
|
end
|
30
30
|
|
31
31
|
def reply_all_with msg
|
data/lib/gmail/thread.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Gmail
|
2
2
|
class Thread < APIResource
|
3
|
-
include
|
4
|
-
include
|
5
|
-
include
|
6
|
-
include
|
7
|
-
include
|
3
|
+
include Base::List
|
4
|
+
include Base::Delete
|
5
|
+
include Base::Get
|
6
|
+
include Base::Modify
|
7
|
+
include Base::Trash
|
8
8
|
|
9
9
|
def messages
|
10
10
|
|
11
11
|
if @values.messages.is_a? Array
|
12
|
-
if @values.messages.first.is_a?
|
12
|
+
if @values.messages.first.is_a? Message
|
13
13
|
@values.messages
|
14
14
|
else
|
15
15
|
@values.messages = Util.convert_to_gmail_object(to_hash[:messages], key="message")
|
data/lib/gmail/version.rb
CHANGED
@@ -27,19 +27,13 @@ module Gmail
|
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
-
should "
|
30
|
+
should "recursively call to_hash on GmailObject" do
|
31
31
|
nested = Gmail::GmailObject.new({ :id => 7, :foo => 'bar' })
|
32
|
-
obj = Gmail::GmailObject.new({ :id => 1
|
33
|
-
|
32
|
+
obj = Gmail::GmailObject.new({ :id => 1})
|
33
|
+
obj.nested = nested
|
34
|
+
expected_hash = { :id => 1, :nested => {:id => 7, :foo => 'bar'} }
|
34
35
|
assert_equal expected_hash, obj.to_hash
|
35
36
|
end
|
36
37
|
|
37
|
-
should "recursively call to_hash on its value" do
|
38
|
-
nested = { :id => 7, :foo => 'bar' }
|
39
|
-
obj = Gmail::GmailObject.new({ :id => 1, :nested => nested })
|
40
|
-
expected_hash = { :id => 1, :nested => nested }
|
41
|
-
assert_equal 7, obj.nested.id
|
42
|
-
assert_equal expected_hash, obj.to_hash
|
43
|
-
end
|
44
38
|
end
|
45
39
|
end
|
data/test/gmail/util_test.rb
CHANGED
@@ -5,11 +5,11 @@ module Gmail
|
|
5
5
|
class UtilTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
should "Symbolize Name should work properly" do
|
8
|
-
assert_equal(({test1
|
8
|
+
assert_equal(({:test1=> "test"}), Gmail::Util.symbolize_names({"test1"=>'test'}))
|
9
9
|
m =Gmail::Message.new test_message
|
10
10
|
assert_equal m, Gmail::Util.symbolize_names(m)
|
11
|
-
assert_equal(({test: {nested:[{coucou: "1", coucou2: "2"}]}}), Gmail::Util.symbolize_names({"test"
|
12
|
-
assert_equal [{coucou: "1", coucou2: "2"}], Gmail::Util.symbolize_names([{"coucou"
|
11
|
+
assert_equal(({test: {nested:[{coucou: "1", coucou2: "2"}]}}), Gmail::Util.symbolize_names({"test"=>{"nested"=>[{"coucou"=>"1","coucou2"=>"2"}]}}))
|
12
|
+
assert_equal [{coucou: "1", coucou2: "2"}], Gmail::Util.symbolize_names([{"coucou"=>"1", "coucou2"=>"2"}])
|
13
13
|
end
|
14
14
|
|
15
15
|
#testing of convert_to_gmail_object is not necessary as it is tested through all other test files
|
data/test/test_data.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
module Gmail
|
2
3
|
module TestData
|
3
4
|
def test_response(body, code=200)
|
@@ -12,88 +13,7 @@ module Gmail
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_draft(params={})
|
15
|
-
{
|
16
|
-
"id": "1490204870554280932",
|
17
|
-
"message": {
|
18
|
-
"id": "14ae456f2ff1e3e4",
|
19
|
-
"threadId": "14ae456f2ff1e3e4",
|
20
|
-
"labelIds": [
|
21
|
-
"DRAFT"
|
22
|
-
],
|
23
|
-
"snippet": "sd Cordialement, Julie",
|
24
|
-
"historyId": "227960",
|
25
|
-
"payload": {
|
26
|
-
"mimeType": "multipart/alternative",
|
27
|
-
"filename": "",
|
28
|
-
"headers": [
|
29
|
-
{
|
30
|
-
"name": "MIME-Version",
|
31
|
-
"value": "1.0"
|
32
|
-
},
|
33
|
-
{
|
34
|
-
"name": "Received",
|
35
|
-
"value": "by 10.64.21.4 with HTTP; Tue, 13 Jan 2015 09:28:31 -0800 (PST)"
|
36
|
-
},
|
37
|
-
{
|
38
|
-
"name": "Date",
|
39
|
-
"value": "Tue, 13 Jan 2015 18:28:31 +0100"
|
40
|
-
},
|
41
|
-
{
|
42
|
-
"name": "Message-ID",
|
43
|
-
"value": "<CAFXNVWSNjE652y4nau3nbWeoJ7RD_UsybHWa9-L6vvRi9j3nFQ@mail.gmail.com>"
|
44
|
-
},
|
45
|
-
{
|
46
|
-
"name": "Subject",
|
47
|
-
"value": ""
|
48
|
-
},
|
49
|
-
{
|
50
|
-
"name": "From",
|
51
|
-
"value": "Julie Desk <julie@juliedesk.com>"
|
52
|
-
},
|
53
|
-
{
|
54
|
-
"name": "Content-Type",
|
55
|
-
"value": "multipart/alternative; boundary=f46d042abf34a36bd9050c8bf335"
|
56
|
-
}
|
57
|
-
],
|
58
|
-
"body": {
|
59
|
-
"size": 0
|
60
|
-
},
|
61
|
-
"parts": [
|
62
|
-
{
|
63
|
-
"partId": "0",
|
64
|
-
"mimeType": "text/plain",
|
65
|
-
"filename": "",
|
66
|
-
"headers": [
|
67
|
-
{
|
68
|
-
"name": "Content-Type",
|
69
|
-
"value": "text/plain; charset=UTF-8"
|
70
|
-
}
|
71
|
-
],
|
72
|
-
"body": {
|
73
|
-
"size": 28,
|
74
|
-
"data": "c2QNCkNvcmRpYWxlbWVudCwNCg0KSnVsaWUNCg=="
|
75
|
-
}
|
76
|
-
},
|
77
|
-
{
|
78
|
-
"partId": "1",
|
79
|
-
"mimeType": "text/html",
|
80
|
-
"filename": "",
|
81
|
-
"headers": [
|
82
|
-
{
|
83
|
-
"name": "Content-Type",
|
84
|
-
"value": "text/html; charset=UTF-8"
|
85
|
-
}
|
86
|
-
],
|
87
|
-
"body": {
|
88
|
-
"size": 154,
|
89
|
-
"data": "PGRpdiBkaXI9Imx0ciI-c2Q8YnIgY2xlYXI9ImFsbCI-PGRpdj48ZGl2IGNsYXNzPSJnbWFpbF9zaWduYXR1cmUiPjxkaXYgZGlyPSJsdHIiPkNvcmRpYWxlbWVudCw8ZGl2Pjxicj48L2Rpdj48ZGl2Pkp1bGllPC9kaXY-PC9kaXY-PC9kaXY-PC9kaXY-DQo8L2Rpdj4NCg=="
|
90
|
-
}
|
91
|
-
}
|
92
|
-
]
|
93
|
-
},
|
94
|
-
"sizeEstimate": 710
|
95
|
-
}
|
96
|
-
}.merge(params)
|
16
|
+
{:id=>"1490204870554280932", :message=>{:id=>"14ae456f2ff1e3e4", :threadId=>"14ae456f2ff1e3e4", :labelIds=>["DRAFT"], :snippet=>"sd Cordialement, Julie", :historyId=>"227960", :payload=>{:mimeType=>"multipart/alternative", :filename=>"", :headers=>[{:name=>"MIME-Version", :value=>"1.0"}, {:name=>"Received", :value=>"by 10.64.21.4 with HTTP; Tue, 13 Jan 2015 09:28:31 -0800 (PST)"}, {:name=>"Date", :value=>"Tue, 13 Jan 2015 18:28:31 +0100"}, {:name=>"Message-ID", :value=>"<CAFXNVWSNjE652y4nau3nbWeoJ7RD_UsybHWa9-L6vvRi9j3nFQ@mail.gmail.com>"}, {:name=>"Subject", :value=>""}, {:name=>"From", :value=>"Julie Desk <julie@juliedesk.com>"}, {:name=>"Content-Type", :value=>"multipart/alternative; boundary=f46d042abf34a36bd9050c8bf335"}], :body=>{:size=>0}, :parts=>[{:partId=>"0", :mimeType=>"text/plain", :filename=>"", :headers=>[{:name=>"Content-Type", :value=>"text/plain; charset=UTF-8"}], :body=>{:size=>28, :data=>"c2QNCkNvcmRpYWxlbWVudCwNCg0KSnVsaWUNCg=="}}, {:partId=>"1", :mimeType=>"text/html", :filename=>"", :headers=>[{:name=>"Content-Type", :value=>"text/html; charset=UTF-8"}], :body=>{:size=>154, :data=>"PGRpdiBkaXI9Imx0ciI-c2Q8YnIgY2xlYXI9ImFsbCI-PGRpdj48ZGl2IGNsYXNzPSJnbWFpbF9zaWduYXR1cmUiPjxkaXYgZGlyPSJsdHIiPkNvcmRpYWxlbWVudCw8ZGl2Pjxicj48L2Rpdj48ZGl2Pkp1bGllPC9kaXY-PC9kaXY-PC9kaXY-PC9kaXY-DQo8L2Rpdj4NCg=="}}]}, :sizeEstimate=>710}} .merge(params)
|
97
17
|
|
98
18
|
end
|
99
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmail-api-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Hobeika
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.4.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.4.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hashie
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 3.3.2
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 3.3.2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,28 +114,28 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: 1.0.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
124
|
+
version: 1.0.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: shoulda
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 3.
|
131
|
+
version: 3.5.0
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 3.
|
138
|
+
version: 3.5.0
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: gem-release
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,6 +160,7 @@ extensions: []
|
|
160
160
|
extra_rdoc_files: []
|
161
161
|
files:
|
162
162
|
- ".gitignore"
|
163
|
+
- ".travis.yml"
|
163
164
|
- CHANGELOG.md
|
164
165
|
- Gemfile
|
165
166
|
- LICENSE
|
@@ -205,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
206
|
requirements:
|
206
207
|
- - ">="
|
207
208
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
209
|
+
version: 1.9.3
|
209
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
211
|
requirements:
|
211
212
|
- - ">="
|