developerreply 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/developerreply.rb +16 -28
- data/lib/developerreply/version.rb +1 -1
- data/spec/developerreply_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8e888ef8cd9719cbc0368a92da5cd8a9e4b638e
|
4
|
+
data.tar.gz: e586a1f6adfd192e14577c632899b1fd5d75b798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0420644727aea2e991e7a5b7cd435fa156b9059a5f32bf7a805bc4af5eac107dd237f664bce26bea7e88d045fa50ee042d07bf6844ba15e4db4bf72be129aa36
|
7
|
+
data.tar.gz: ec80b1aed01be5813f5036d57263f331fdee12d1051624193f4e8557d63e2f5c976098ffb571c97c8ac4e722983044aedc04a82943d5509c6b6df5472fabac9b
|
data/lib/developerreply.rb
CHANGED
@@ -38,53 +38,41 @@ module Developerreply
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def create(options={})
|
41
|
-
cookie = attempt_login_and_return_cookie
|
42
|
-
|
43
41
|
hostname = options[:hostname]
|
44
42
|
url = options[:url]
|
45
|
-
payload =
|
43
|
+
payload = {
|
44
|
+
hostname: hostname,
|
45
|
+
url: url,
|
46
|
+
api_user: Developerreply.username,
|
47
|
+
api_key: Developerreply.password
|
48
|
+
}
|
46
49
|
|
47
50
|
resp = Developerreply.request.post do |req|
|
48
|
-
req.path = "/
|
51
|
+
req.path = "/api/parse.set.json"
|
49
52
|
req.body = payload
|
50
|
-
req.headers["Cookie"] = cookie
|
51
53
|
end
|
52
54
|
|
53
|
-
if resp.
|
54
|
-
|
55
|
+
if resp.body["error"]
|
56
|
+
error_message = resp.body["error"]["message"]
|
57
|
+
raise "Unable to create hostname and url: #{error_message}"
|
55
58
|
else
|
56
|
-
|
59
|
+
return true
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
60
63
|
private
|
61
64
|
|
62
|
-
def login_payload
|
63
|
-
"login[username]=#{Developerreply.username}&login[password]=#{Developerreply.password}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def attempt_login_and_return_cookie
|
67
|
-
cookie = ""
|
68
|
-
|
69
|
-
resp = Developerreply.request.post '/login', login_payload
|
70
|
-
|
71
|
-
if resp.status == 302 # for SendGrid's auth, a 302 is a successful login where a 200 is not successful... yeah, I know.
|
72
|
-
set_cookie_header = resp.headers["set-cookie"]
|
73
|
-
cookie = set_cookie_header.split(";")[0]
|
74
|
-
end
|
75
|
-
|
76
|
-
raise "Authentication failed" if cookie == ""
|
77
|
-
|
78
|
-
cookie
|
79
|
-
end
|
80
|
-
|
81
65
|
def setup_request!
|
82
66
|
options = {
|
83
|
-
|
67
|
+
#:headers => {'Accept' => "application/json"},
|
68
|
+
:url => "https://api.sendgrid.com",
|
84
69
|
:ssl => {:verify => false}
|
85
70
|
}
|
86
71
|
|
87
72
|
Developerreply.request = ::Faraday::Connection.new(options) do |builder|
|
73
|
+
builder.use ::Faraday::Request::UrlEncoded
|
74
|
+
builder.use ::FaradayMiddleware::ParseJson
|
75
|
+
builder.use ::FaradayMiddleware::FollowRedirects
|
88
76
|
builder.adapter ::Faraday.default_adapter
|
89
77
|
end
|
90
78
|
end
|
data/spec/developerreply_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: developerreply
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scottmotte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|