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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9214f4fe5d0a7098934c415360dbe571ce3328a8
4
- data.tar.gz: 261715231d1d1fdd6e528e59b50d881751b6f4a2
3
+ metadata.gz: c8e888ef8cd9719cbc0368a92da5cd8a9e4b638e
4
+ data.tar.gz: e586a1f6adfd192e14577c632899b1fd5d75b798
5
5
  SHA512:
6
- metadata.gz: 3781a92263ccfd330b32e69768abb3ac13e02bdb2634e4935b5b661036ebfdb47d0c868276caf8deaac78db5b4049ed5d2764c8b682f49d5df068eb55bc6a2f9
7
- data.tar.gz: 6b262d6ad9cb5871930314a8581ed6d309582f6b0acb09c6ad7600bc2bc1ce2221cea824c8ef9f509d44f0828e4824c2284d58f80de6db792f6dbcaa41fa9543
6
+ metadata.gz: 0420644727aea2e991e7a5b7cd435fa156b9059a5f32bf7a805bc4af5eac107dd237f664bce26bea7e88d045fa50ee042d07bf6844ba15e4db4bf72be129aa36
7
+ data.tar.gz: ec80b1aed01be5813f5036d57263f331fdee12d1051624193f4e8557d63e2f5c976098ffb571c97c8ac4e722983044aedc04a82943d5509c6b6df5472fabac9b
@@ -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 = "reply_option[hostname]=#{hostname}&reply_option[url]=#{url}"
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 = "/developer/reply"
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.status == 302 # for SendGrid's response here, a 302 is a successful create... yea, I know.
54
- return true
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
- raise "Unable to create hostname and url at /developer/reply"
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
- :url => "https://sendgrid.com",
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
@@ -1,3 +1,3 @@
1
1
  module Developerreply
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -9,7 +9,7 @@ describe Developerreply do
9
9
  subject.password = nil
10
10
  end
11
11
 
12
- it { expect(subject::VERSION).to eq("0.0.2") }
12
+ it { expect(subject::VERSION).to eq("0.0.3") }
13
13
  end
14
14
 
15
15
  describe "setting values" do
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.2
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-25 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday