context_io 1.0.0.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.md +190 -0
- data/README.md +147 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/context_io.gemspec +45 -0
- data/lib/context_io.rb +104 -0
- data/lib/context_io/account.rb +143 -0
- data/lib/context_io/account/contact.rb +59 -0
- data/lib/context_io/account/email_address.rb +33 -0
- data/lib/context_io/account/files.rb +58 -0
- data/lib/context_io/account/sources.rb +83 -0
- data/lib/context_io/account/sync.rb +34 -0
- data/lib/context_io/account/threads.rb +35 -0
- data/lib/context_io/connection.rb +25 -0
- data/lib/context_io/oauth_provider.rb +33 -0
- data/lib/context_io/shared/connect_token.rb +35 -0
- data/lib/context_io/shared/discovery.rb +31 -0
- data/lib/context_io/shared/folder.rb +57 -0
- data/lib/context_io/shared/message.rb +112 -0
- data/lib/context_io/shared/webhook.rb +43 -0
- data/lib/context_io/utilities/api_call_made.rb +5 -0
- data/lib/context_io/utilities/call_helpers.rb +145 -0
- data/lib/context_io/utilities/collection_helper.rb +41 -0
- data/lib/context_io/utilities/deleted_resource.rb +15 -0
- data/lib/context_io/utilities/request.rb +21 -0
- data/lib/context_io/utilities/valid_parameters/get_params.rb +60 -0
- data/lib/context_io/utilities/valid_parameters/post_params.rb +48 -0
- data/lib/context_io/version.rb +3 -0
- metadata +204 -0
data/lib/context_io.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'context_io/account'
|
2
|
+
require 'context_io/connection'
|
3
|
+
require 'context_io/oauth_provider'
|
4
|
+
|
5
|
+
require 'context_io/account/contact'
|
6
|
+
require 'context_io/account/email_address'
|
7
|
+
require 'context_io/account/files'
|
8
|
+
require 'context_io/account/sources'
|
9
|
+
require 'context_io/account/sync'
|
10
|
+
require 'context_io/account/threads'
|
11
|
+
|
12
|
+
require 'context_io/shared/connect_token'
|
13
|
+
require 'context_io/shared/discovery'
|
14
|
+
require 'context_io/shared/folder'
|
15
|
+
require 'context_io/shared/message'
|
16
|
+
require 'context_io/shared/webhook'
|
17
|
+
|
18
|
+
require 'context_io/utilities/api_call_made'
|
19
|
+
require 'context_io/utilities/call_helpers'
|
20
|
+
require 'context_io/utilities/collection_helper'
|
21
|
+
require 'context_io/utilities/deleted_resource'
|
22
|
+
require 'context_io/utilities/request'
|
23
|
+
require 'context_io/utilities/valid_parameters/get_params'
|
24
|
+
require 'context_io/utilities/valid_parameters/post_params'
|
25
|
+
|
26
|
+
require "erb"
|
27
|
+
|
28
|
+
module ContextIO
|
29
|
+
class ContextIO
|
30
|
+
include CollectionHelper
|
31
|
+
include CallHelpers
|
32
|
+
attr_reader :connection, :call_url
|
33
|
+
def initialize(key:, secret:)
|
34
|
+
@connection = Connection.new(key, secret)
|
35
|
+
@call_url = "/2.0"
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_accounts(**kwargs)
|
39
|
+
collection_return(url: "#{call_url}/accounts",
|
40
|
+
klass: Account,
|
41
|
+
valid_params: ValidGetParams::ACCOUNTS,
|
42
|
+
given_params: kwargs)
|
43
|
+
end
|
44
|
+
|
45
|
+
def post_account(type: "IMAP", **kwargs)
|
46
|
+
given_params = kwargs.merge(type: type)
|
47
|
+
account = call_api_return_new_object(klass: Account,
|
48
|
+
url: "#{call_url}/accounts",
|
49
|
+
method: :post,
|
50
|
+
valid_params: ValidPostParams::ACCOUNTS,
|
51
|
+
given_params: given_params)
|
52
|
+
return_post_api_call_made(account)
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_connect_tokens
|
56
|
+
collection_return(url: "#{call_url}/connect_tokens",
|
57
|
+
klass: ConnectToken)
|
58
|
+
end
|
59
|
+
|
60
|
+
def post_connect_token(callback_url: , **kwargs)
|
61
|
+
given_params = kwargs.merge(callback_url: callback_url)
|
62
|
+
token = call_api_return_new_object(klass: ConnectToken,
|
63
|
+
url: "#{call_url}/connect_tokens",
|
64
|
+
method: :post,
|
65
|
+
valid_params: ValidPostParams::CONNECT_TOKEN,
|
66
|
+
given_params: given_params)
|
67
|
+
return_post_api_call_made(token)
|
68
|
+
end
|
69
|
+
|
70
|
+
def discovery(email:)
|
71
|
+
Discovery.new(parent: self, email: email).get
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_oauth_providers
|
75
|
+
collection_return(url: "#{call_url}/oauth_providers",
|
76
|
+
klass: OauthProvider)
|
77
|
+
end
|
78
|
+
|
79
|
+
def post_oauth_provider(type:, provider_consumer_key:, provider_consumer_secret:)
|
80
|
+
given_params = [type, provider_consumer_key, provider_consumer_secret]
|
81
|
+
provider = call_api_return_new_object(klass: OauthProvider,
|
82
|
+
url: "#{call_url}/oauth_provider",
|
83
|
+
method: :post,
|
84
|
+
valid_params: ValidPostParams::OAUTH_PROVIDER,
|
85
|
+
given_params: given_params)
|
86
|
+
return_post_api_call_made(provider)
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_webhooks
|
90
|
+
collection_return(url: "#{call_url}/webhooks",
|
91
|
+
klass: Webhook)
|
92
|
+
end
|
93
|
+
|
94
|
+
def post_webhook(callback_url:, **kwargs)
|
95
|
+
given_params = kwargs.merge(callback_url: callback_url)
|
96
|
+
token = call_api_return_new_object(klass: Webhook,
|
97
|
+
url: "#{call_url}/webhooks",
|
98
|
+
method: :post,
|
99
|
+
valid_params: ValidPostParams::WEBHOOK,
|
100
|
+
given_params: given_params)
|
101
|
+
return_post_api_call_made(token)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require "context_io/utilities/collection_helper"
|
2
|
+
require "context_io/utilities/call_helpers"
|
3
|
+
module ContextIO
|
4
|
+
class Account
|
5
|
+
include ContextIO::CallHelpers
|
6
|
+
ACCOUNT_READERS = %I(username created suspended email_addresses first_name last_name
|
7
|
+
password_expired sources resource_url)
|
8
|
+
private
|
9
|
+
attr_reader :parent
|
10
|
+
|
11
|
+
public
|
12
|
+
attr_accessor :api_call_made
|
13
|
+
attr_reader :id, :success, :connection, :status, *ACCOUNT_READERS
|
14
|
+
def initialize(parent:,
|
15
|
+
identifier: nil,
|
16
|
+
response: nil,
|
17
|
+
status: nil,
|
18
|
+
success: nil,
|
19
|
+
api_call_made: nil)
|
20
|
+
@parent = parent
|
21
|
+
@connection = parent.connection
|
22
|
+
@id = identifier
|
23
|
+
@status = status
|
24
|
+
@success = success
|
25
|
+
@api_call_made = api_call_made
|
26
|
+
if response
|
27
|
+
parse_response(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def call_url
|
32
|
+
build_url("accounts", id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def post(**kwargs)
|
36
|
+
call_api_return_updated_object(klass: Account,
|
37
|
+
method: :post,
|
38
|
+
identifier: id,
|
39
|
+
url: call_url,
|
40
|
+
valid_params: ValidPostParams::ACCOUNT,
|
41
|
+
given_params: kwargs)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_connect_tokens
|
45
|
+
collection_return(url: "#{call_url}/connect_tokens",
|
46
|
+
klass: ConnectToken)
|
47
|
+
end
|
48
|
+
|
49
|
+
def post_connect_token(callback_url:, **kwargs)
|
50
|
+
given_params = kwargs.merge(callback_url: callback_url)
|
51
|
+
token = call_api_return_new_object(klass: ConnectToken,
|
52
|
+
url: "#{call_url}/connect_tokens",
|
53
|
+
method: :post,
|
54
|
+
valid_params: ValidPostParams::CONNECT_TOKEN,
|
55
|
+
given_params: given_params)
|
56
|
+
return_post_api_call_made(token)
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_contacts(**kwargs)
|
60
|
+
contact_collection_return(url: "#{call_url}/contacts",
|
61
|
+
valid_params: ValidGetParams::CONTACTS,
|
62
|
+
given_params: kwargs)
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_email_addresses
|
66
|
+
collection_return(url: "#{call_url}/email_addresses",
|
67
|
+
klass: EmailAddress)
|
68
|
+
end
|
69
|
+
|
70
|
+
def post_email_address(email_address:)
|
71
|
+
given_params = { email_address: email_address }
|
72
|
+
email = call_api_return_new_object(klass: EmailAddress,
|
73
|
+
url: "#{call_url}/email_addresses",
|
74
|
+
method: :post,
|
75
|
+
valid_params: [:email_address],
|
76
|
+
given_params: given_params)
|
77
|
+
return_post_api_call_made(email)
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_files(**kwargs)
|
81
|
+
collection_return(url: "#{call_url}/files",
|
82
|
+
klass: Files,
|
83
|
+
valid_params: ValidGetParams::FILES,
|
84
|
+
given_params: kwargs)
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_messages(**kwargs)
|
88
|
+
collection_return(url: "#{call_url}/messages",
|
89
|
+
klass: Message,
|
90
|
+
valid_params: ValidGetParams::MESSAGES,
|
91
|
+
given_params: kwargs)
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_sources(**kwargs)
|
95
|
+
collection_return(url: "#{call_url}/sources",
|
96
|
+
klass: Sources,
|
97
|
+
valid_params: ValidGetParams::SOURCES,
|
98
|
+
given_params: kwargs)
|
99
|
+
end
|
100
|
+
|
101
|
+
def post_source(email:, server:, username:, use_ssl:, port:, type: "IMAP", **kwargs)
|
102
|
+
given_params = kwargs.merge(email: email,
|
103
|
+
server: server,
|
104
|
+
username: username,
|
105
|
+
use_ssl: use_ssl,
|
106
|
+
port: port,
|
107
|
+
type: type)
|
108
|
+
token = call_api_return_new_object(klass: Sources,
|
109
|
+
url: "#{call_url}/sources",
|
110
|
+
method: :post,
|
111
|
+
valid_params: ValidPostParams::SOURCES,
|
112
|
+
given_params: given_params)
|
113
|
+
return_post_api_call_made(token)
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_sync
|
117
|
+
Sync.new(parent: self).get
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_threads(**kwargs)
|
121
|
+
call_api_return_new_object(klass: Threads,
|
122
|
+
url: "#{call_url}/threads",
|
123
|
+
valid_params: ValidGetParams::THREADS,
|
124
|
+
given_params: kwargs)
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_webhooks
|
128
|
+
collection_return(url: "#{call_url}/webhooks",
|
129
|
+
klass: Webhook)
|
130
|
+
end
|
131
|
+
|
132
|
+
def post_webhook(callback_url:, failure_notif_url:, **kwargs)
|
133
|
+
given_params = kwargs.merge(callback_url: callback_url,
|
134
|
+
failure_notif_url: failure_notif_url)
|
135
|
+
token = call_api_return_new_object(klass: Webhook,
|
136
|
+
url: "#{call_url}/webhooks",
|
137
|
+
method: :post,
|
138
|
+
valid_params: ValidPostParams::WEBHOOKS,
|
139
|
+
given_params: given_params)
|
140
|
+
return_post_api_call_made(token)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ContextIO
|
2
|
+
class Contact
|
3
|
+
include ContextIO::CallHelpers
|
4
|
+
CONTACT_READERS = %I(emails name thumbnail last_received last_sent count sent_count
|
5
|
+
received_count sent_from_account_count query email resource_url)
|
6
|
+
private
|
7
|
+
attr_reader :parent
|
8
|
+
|
9
|
+
public
|
10
|
+
attr_accessor :api_call_made
|
11
|
+
attr_reader :response, :status, :parent, :connection, :success, :email,
|
12
|
+
*CONTACT_READERS
|
13
|
+
def initialize(parent:,
|
14
|
+
identifier: nil,
|
15
|
+
response: nil,
|
16
|
+
status: nil,
|
17
|
+
success: nil,
|
18
|
+
api_call_made: nil)
|
19
|
+
@parent = parent
|
20
|
+
@connection = parent.connection
|
21
|
+
@email = identifier
|
22
|
+
@status = status
|
23
|
+
@success = success
|
24
|
+
@api_call_made = api_call_made
|
25
|
+
if response
|
26
|
+
parse_response(response)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def encoded_email
|
31
|
+
ERB::Util.url_encode(email)
|
32
|
+
end
|
33
|
+
|
34
|
+
def call_url
|
35
|
+
build_url("contacts", encoded_email)
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_files(**kwargs)
|
39
|
+
collection_return(url: "#{call_url}/files",
|
40
|
+
klass: Files,
|
41
|
+
valid_params: ValidGetParams::CONTACT_FILES,
|
42
|
+
given_params: kwargs)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_messages(**kwargs)
|
46
|
+
collection_return(url: "#{call_url}/messages",
|
47
|
+
klass: Message,
|
48
|
+
valid_params: ValidGetParams::CONTACT_MESSAGES,
|
49
|
+
given_params: kwargs)
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_threads(**kwargs)
|
53
|
+
call_api_return_new_object(klass: Threads,
|
54
|
+
url: "#{call_url}/threads",
|
55
|
+
valid_params: ValidGetParams::THREADS,
|
56
|
+
given_params: kwargs)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ContextIO
|
2
|
+
class EmailAddress
|
3
|
+
include ContextIO::CallHelpers
|
4
|
+
EMAIL_ATTRS = %I(validated primary resource_url)
|
5
|
+
|
6
|
+
private
|
7
|
+
attr_reader :parent
|
8
|
+
|
9
|
+
public
|
10
|
+
attr_accessor :api_call_made
|
11
|
+
attr_reader :response, :status, :connection, :success, :email, *EMAIL_ATTRS
|
12
|
+
def initialize(parent:,
|
13
|
+
identifier: nil,
|
14
|
+
response: nil,
|
15
|
+
status: nil,
|
16
|
+
success: nil,
|
17
|
+
api_call_made: nil)
|
18
|
+
@parent = parent
|
19
|
+
@connection = parent.connection
|
20
|
+
@email = identifier
|
21
|
+
@status = status
|
22
|
+
@success = success
|
23
|
+
@api_call_made = api_call_made
|
24
|
+
if response
|
25
|
+
parse_response(response)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def call_url
|
30
|
+
build_url("email_addresses", email)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module ContextIO
|
2
|
+
class Files
|
3
|
+
include ContextIO::CallHelpers
|
4
|
+
FILE_READERS = %I(size type subject date date_indexed addresses person_info
|
5
|
+
file_name file_name_structure body_section supports_preview
|
6
|
+
is_embedded content_disposition content_id message_id
|
7
|
+
email_message_id gmail_message_id gmail_thread_id email_addresses
|
8
|
+
created first_name id last_name resource_url sources is_tnef_part)
|
9
|
+
|
10
|
+
private
|
11
|
+
attr_reader :parent
|
12
|
+
|
13
|
+
public
|
14
|
+
attr_accessor :api_call_made
|
15
|
+
attr_reader :connection, :response, :status, :success, :file_id, *FILE_READERS
|
16
|
+
def initialize(parent:,
|
17
|
+
identifier: nil,
|
18
|
+
response: nil,
|
19
|
+
status: nil,
|
20
|
+
success: nil,
|
21
|
+
api_call_made: nil)
|
22
|
+
@parent = parent
|
23
|
+
@connection = parent.connection
|
24
|
+
@file_id = identifier
|
25
|
+
@status = status
|
26
|
+
@success = success
|
27
|
+
@api_call_made = api_call_made
|
28
|
+
if response
|
29
|
+
parse_response(response)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def call_url
|
34
|
+
build_url("files", file_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def contact_url?
|
38
|
+
parent.call_url.include?("/contacts/")
|
39
|
+
end
|
40
|
+
|
41
|
+
def contact_url_error
|
42
|
+
raise StandardError, "This method can only be called from '2.0/accounts/:account/file/:file_id'" if contact_url?
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_content(**kwargs)
|
46
|
+
contact_url_error
|
47
|
+
call_api_return_new_object(klass: Files,
|
48
|
+
url: "#{call_url}/content",
|
49
|
+
valid_params: ValidGetParams::FILE_CONTENT,
|
50
|
+
given_params: kwargs)
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_related
|
54
|
+
contact_url_error
|
55
|
+
get_request(url: "#{call_url}/related")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module ContextIO
|
2
|
+
class Sources
|
3
|
+
include ContextIO::CallHelpers
|
4
|
+
include ContextIO::CollectionHelper
|
5
|
+
SOURCE_READERS = %I(username status type label use_ssl resource_url server
|
6
|
+
port mailserviceAccountId callbackUrl delimiter
|
7
|
+
authentication_type sync_flags type browser_redirect_url)
|
8
|
+
|
9
|
+
private
|
10
|
+
attr_reader :parent
|
11
|
+
|
12
|
+
public
|
13
|
+
attr_accessor :api_call_made
|
14
|
+
attr_reader :status, :success, :connection, :message_id, :response, *SOURCE_READERS
|
15
|
+
def initialize(parent:,
|
16
|
+
identifier: nil,
|
17
|
+
response: nil,
|
18
|
+
status: nil,
|
19
|
+
success: nil,
|
20
|
+
api_call_made: nil)
|
21
|
+
@status = status
|
22
|
+
@success = success
|
23
|
+
@parent = parent
|
24
|
+
@connection = parent.connection
|
25
|
+
@label = identifier
|
26
|
+
@api_call_made = api_call_made
|
27
|
+
if response
|
28
|
+
parse_response(response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def call_url
|
33
|
+
build_url("sources", label)
|
34
|
+
end
|
35
|
+
|
36
|
+
def post(**kwargs)
|
37
|
+
src = call_api_return_updated_object(klass: Sources,
|
38
|
+
url: call_url,
|
39
|
+
identifier: label,
|
40
|
+
method: :post,
|
41
|
+
valid_params: ValidPostParams::SOURCE,
|
42
|
+
given_params: kwargs)
|
43
|
+
return_post_api_call_made(src)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_folders(**kwargs)
|
47
|
+
collection_return(url: "#{call_url}/folders",
|
48
|
+
klass: Folder,
|
49
|
+
valid_params: ValidGetParams::FOLDERS_SOURCES,
|
50
|
+
given_params: kwargs)
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_folder(folder:, **kwargs)
|
54
|
+
url = "#{call_url}/folders/#{folder}"
|
55
|
+
call_api_return_new_object(klass: Folder,
|
56
|
+
url: url,
|
57
|
+
valid_params: ValidGetParams::SOURCE_FOLDER,
|
58
|
+
given_params: kwargs)
|
59
|
+
end
|
60
|
+
|
61
|
+
def sync
|
62
|
+
Sync.new(parent: self).get
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_connect_tokens
|
66
|
+
collection_return(url: "#{call_url}/connect_tokens",
|
67
|
+
klass: ConnectToken)
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_connect_token(token:)
|
71
|
+
call_api_return_new_object(klass: ConnectToken,
|
72
|
+
url: "#{call_url}/connect_tokens/#{token}")
|
73
|
+
end
|
74
|
+
|
75
|
+
def post_connect_token(callback_url:)
|
76
|
+
call_api_return_new_object(klass: ConnectToken,
|
77
|
+
url: "#{call_url}/connect_tokens",
|
78
|
+
method: :post,
|
79
|
+
valid_params: ValidPostParams::SOURCE_CONNECT_TOKEN,
|
80
|
+
given_params: { callback_url: callback_url })
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|