cheetahmails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cheetahmails.rb +59 -43
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aee984ac6a9285db5c84668cfe43c3984168a747
|
4
|
+
data.tar.gz: 17caa4d68620ab641c8052048ad26129c1c4a3a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 650fff6a0faf9565dfd90f2a789ab6bec812b97bac59c073b3e25d2674706bc8ccd5784e9917b43c5cf117e111b2d3ef298ca75d9d415c273a5fb7182c3a466b
|
7
|
+
data.tar.gz: f52b315512e4567510e989ac18aeb0df8c5742336ad3b2948ed018f4f5467b6e09fecedaeba2cbbc4f3342ae1c091def25dedff2ac0ff04c76b2d511ff25d6e8
|
data/lib/cheetahmails.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'faraday'
|
2
2
|
require 'json'
|
3
3
|
require 'redis'
|
4
4
|
|
5
5
|
module Cheetahmails
|
6
|
-
|
7
|
-
base_uri 'https://login.eccmp.com'
|
6
|
+
@base_uri = 'https://login.eccmp.com'
|
8
7
|
|
9
8
|
class << self
|
10
9
|
attr_accessor :configuration
|
11
10
|
end
|
12
11
|
|
13
|
-
def self.
|
12
|
+
def self.get_token(clear_cache = false)
|
13
|
+
tries ||= 2
|
14
14
|
|
15
15
|
redis = Redis.new(Cheetahmails.configuration.redis)
|
16
16
|
|
@@ -18,21 +18,26 @@ module Cheetahmails
|
|
18
18
|
|
19
19
|
if not token = redis.get("cheetahmails_access_token")
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
faraday = Faraday.new(:url => @base_uri) do |faraday|
|
22
|
+
faraday.request :url_encoded # form-encode POST params
|
23
|
+
#faraday.response :logger # log requests to STDOUT
|
24
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
25
|
+
end
|
26
|
+
|
27
|
+
params = {
|
28
|
+
"username" => Cheetahmails.configuration.username,
|
29
|
+
"password" => Cheetahmails.configuration.password,
|
30
|
+
"grant_type" => "password"
|
28
31
|
}
|
29
32
|
|
30
|
-
response =
|
33
|
+
response = faraday.post '/services2/authorization/oAuth2/Token', params
|
34
|
+
|
35
|
+
raise RetryException, response.status.to_s + " " + response.body if response.status != 200
|
31
36
|
|
32
37
|
begin
|
33
38
|
jsonresponse = JSON.parse(response.body)
|
34
39
|
rescue JSON::ParserError => error
|
35
|
-
|
40
|
+
raise response.status.to_s + " " + response.body
|
36
41
|
end
|
37
42
|
|
38
43
|
if token = jsonresponse["access_token"]
|
@@ -44,35 +49,44 @@ module Cheetahmails
|
|
44
49
|
|
45
50
|
token
|
46
51
|
|
52
|
+
rescue RetryException => e
|
53
|
+
if (tries -= 1) > 0
|
54
|
+
retry
|
55
|
+
else
|
56
|
+
raise e
|
57
|
+
end
|
47
58
|
end
|
48
59
|
|
49
|
-
def self.
|
60
|
+
def self.find_list_member(email)
|
50
61
|
tries ||= 2
|
51
62
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
faraday = Faraday.new(:url => @base_uri) do |faraday|
|
64
|
+
faraday.request :url_encoded # form-encode POST params
|
65
|
+
#faraday.response :logger # log requests to STDOUT
|
66
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
67
|
+
end
|
68
|
+
|
69
|
+
faraday.headers["Authorization"] = "Bearer " + self.get_token(tries < 2)
|
70
|
+
faraday.headers["Content-Type"] = "application/json"
|
71
|
+
faraday.headers["Accept"] = "application/json"
|
72
|
+
|
73
|
+
params = {
|
74
|
+
"viewName" => Cheetahmails.configuration.view_name,
|
75
|
+
"prop" => '', #first_name,last_name
|
76
|
+
"columnName" => "email_address",
|
77
|
+
"operation" => "=",
|
78
|
+
"param" => email
|
65
79
|
}
|
66
80
|
|
67
|
-
response =
|
81
|
+
response = faraday.get '/services2/api/SearchRecords', params
|
68
82
|
|
69
83
|
begin
|
70
84
|
jsonresponse = JSON.parse(response.body)
|
71
85
|
rescue JSON::ParserError => error
|
72
|
-
|
86
|
+
raise response.status.to_s + " " + response.body
|
73
87
|
end
|
74
88
|
|
75
|
-
raise RetryException, jsonresponse["message"] if response.
|
89
|
+
raise RetryException, jsonresponse["message"] if response.status == 401
|
76
90
|
|
77
91
|
begin
|
78
92
|
id = jsonresponse[0]["id"]
|
@@ -86,7 +100,7 @@ module Cheetahmails
|
|
86
100
|
end
|
87
101
|
end
|
88
102
|
|
89
|
-
def self.
|
103
|
+
def self.add_list_member(api_post_id, key_data)
|
90
104
|
tries ||= 2
|
91
105
|
|
92
106
|
data = []
|
@@ -97,26 +111,28 @@ module Cheetahmails
|
|
97
111
|
|
98
112
|
data = {"apiPostId" => api_post_id, "data" => data}
|
99
113
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
"Accept" => "application/json"
|
105
|
-
},
|
106
|
-
body: data.to_json
|
107
|
-
}
|
114
|
+
faraday = Faraday.new(:url => @base_uri) do |faraday|
|
115
|
+
#faraday.response :logger # log requests to STDOUT
|
116
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
117
|
+
end
|
108
118
|
|
109
|
-
response =
|
119
|
+
response = faraday.post do |req|
|
120
|
+
req.url '/services2/api/Recipients'
|
121
|
+
req.headers["Authorization"] = "Bearer " + self.get_token(tries < 2)
|
122
|
+
req.headers["Content-Type"] = "application/json"
|
123
|
+
req.headers["Accept"] = "application/json"
|
124
|
+
req.body = data.to_json
|
125
|
+
end
|
110
126
|
|
111
127
|
begin
|
112
128
|
jsonresponse = JSON.parse(response.body)
|
113
129
|
rescue JSON::ParserError => error
|
114
|
-
|
130
|
+
raise response.status.to_s + " " + response.body
|
115
131
|
end
|
116
132
|
|
117
|
-
raise RetryException, jsonresponse["message"] if response.
|
133
|
+
raise RetryException, jsonresponse["message"] if response.status == 401
|
118
134
|
|
119
|
-
return response.
|
135
|
+
return response.status == 200 && jsonresponse["success"]
|
120
136
|
|
121
137
|
rescue RetryException => e
|
122
138
|
if (tries -= 1) > 0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheetahmails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Holder
|
@@ -11,19 +11,19 @@ cert_chain: []
|
|
11
11
|
date: 2015-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.9.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.9.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: redis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|