milkman 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/.travis.yml +1 -1
- data/lib/milkman/version.rb +1 -1
- data/spec/milkman/authorizer_spec.rb +8 -8
- data/spec/milkman/cli_spec.rb +1 -1
- data/spec/milkman/client_spec.rb +3 -3
- data/spec/milkman/request_spec.rb +8 -8
- data/spec/milkman/utility_spec.rb +8 -8
- data/spec/milkman_spec.rb +2 -2
- data/spec/spec_helper.rb +8 -0
- 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: 8f70e86ed17fee9abd767258828429e32331dc7e
|
4
|
+
data.tar.gz: 041527d2354dcb3677e501db286f68e6b5fed53d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d22bc948d10b6db10cb2a230315d14b802658d7b7a1912db053a28cc515597eb1a462839e2f7832cabcecfc9c0b68812404d25ed4040bf286821ed3c931a40d1
|
7
|
+
data.tar.gz: 95221cd07e2073ff65c43c0e84103bb55046d4791f00fa5e2be8c08089129b5330cf95e68edc22310ad3568d52d85650f7e3591823dc335b0f0085dfc0a5231d
|
data/.travis.yml
CHANGED
data/lib/milkman/version.rb
CHANGED
@@ -13,7 +13,7 @@ module Milkman
|
|
13
13
|
hash = { api_key: "<api_key>", shared_secret: "<shared_secret>", format: "json", perms: "delete" }
|
14
14
|
|
15
15
|
client = described_class.new(options)
|
16
|
-
client.options.
|
16
|
+
expect(client.options).to eq hash
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -21,7 +21,7 @@ module Milkman
|
|
21
21
|
context ".authorize" do
|
22
22
|
|
23
23
|
it "authorizes" do
|
24
|
-
described_class.
|
24
|
+
expect_any_instance_of(described_class).to receive(:authorize)
|
25
25
|
described_class.authorize options
|
26
26
|
end
|
27
27
|
|
@@ -37,26 +37,26 @@ module Milkman
|
|
37
37
|
{"rsp" => {"auth" => {"user" => {"username" => "<username>"}, "token" => "<token>"}}}
|
38
38
|
end
|
39
39
|
|
40
|
-
before { STDIN.
|
40
|
+
before { allow(STDIN).to receive(:gets).and_return "<frob>" }
|
41
41
|
|
42
42
|
it "makes a call to the RTM API" do
|
43
|
-
Milkman::Request.
|
43
|
+
allow(Milkman::Request).to receive(:call).with(any_args).and_return response
|
44
44
|
capture_stdout { described_class.authorize options }
|
45
45
|
end
|
46
46
|
|
47
47
|
context "output" do
|
48
48
|
|
49
49
|
before do
|
50
|
-
Milkman::Request.
|
50
|
+
allow(Milkman::Request).to receive(:call).with(any_args).and_return response
|
51
51
|
end
|
52
52
|
|
53
53
|
it "notifies the user of entering the frob value" do
|
54
|
-
described_class.
|
55
|
-
output.
|
54
|
+
allow_any_instance_of(described_class).to receive(:frob_message_url).and_return "<url>"
|
55
|
+
expect(output).to include "\nCopy the URL below and follow the steps on Remember The Milk (RTM) to authorize Milkman:\n\n<url>\n\nOnce you've authorized Milkman, you'll receive a hash called 'frob' from Remember The Milk. The page from Remember The Milk will list something like the following: 'No callback URL specified for this API key. Your frob value is YOUR_FROB'. Copy and paste that YOUR_FROB value below and press <enter>:"
|
56
56
|
end
|
57
57
|
|
58
58
|
it "notifies the user of the received auth token, API key and shared secret" do
|
59
|
-
output.
|
59
|
+
expect(output).to include "<username>, you've successfully authorized Milkman with Remember The Milk. As you can see we've received your username and an authorization token. Both this auth token, your API key and shared secret should be saved for later use. You can either save them in a YAML file and load them in your application, include them in the Ruby script where you're using this gem or set them as environment variables. That's completely up to you.\n\nBoth the auth token, API key and shared secret are listed below. Save them using one of the methods above (or perhaps another solution) as you'll need all of them to use Milkman in your own project. Oh, and Remember... The Milk!\n\n\tapi_key: <api_key>\n\tshared_secret: <shared_secret>\n\tauth_token: <token>"
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
data/spec/milkman/cli_spec.rb
CHANGED
@@ -4,7 +4,7 @@ module Milkman
|
|
4
4
|
describe CLI do
|
5
5
|
|
6
6
|
it "authorizes" do
|
7
|
-
Authorizer.
|
7
|
+
expect(Authorizer).to receive(:authorize).with(api_key: "foo", shared_secret: "bar")
|
8
8
|
subject.authorize("foo", "bar")
|
9
9
|
end
|
10
10
|
|
data/spec/milkman/client_spec.rb
CHANGED
@@ -13,7 +13,7 @@ module Milkman
|
|
13
13
|
hash = { api_key: "foo", shared_secret: "bar", format: "json", perms: "delete" }
|
14
14
|
|
15
15
|
client = described_class.new(options)
|
16
|
-
client.options.
|
16
|
+
expect(client.options).to eq hash
|
17
17
|
end
|
18
18
|
|
19
19
|
context "when the required API key and shared secret aren't specified" do
|
@@ -52,7 +52,7 @@ module Milkman
|
|
52
52
|
context "when both the API key and shared secret are specified" do
|
53
53
|
|
54
54
|
it "doesn't raise a NoMilkError" do
|
55
|
-
expect {
|
55
|
+
expect { described_class.new(options) }.not_to raise_error
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
@@ -62,7 +62,7 @@ module Milkman
|
|
62
62
|
context "#get" do
|
63
63
|
|
64
64
|
it "requests a call to the RTM API with the specified method" do
|
65
|
-
Milkman::Request.
|
65
|
+
expect(Milkman::Request).to receive(:call).with "http://api.rememberthemilk.com/services/rest/?api_key=foo&shared_secret=bar&perms=delete&format=json&method=method&api_sig=57c35d820267ab89717e291d619860d2"
|
66
66
|
|
67
67
|
client = described_class.new(options)
|
68
68
|
client.get "method"
|
@@ -6,24 +6,24 @@ module Milkman
|
|
6
6
|
let(:url) { "#{BASE_URL}?foo=bar" }
|
7
7
|
|
8
8
|
let(:response) do
|
9
|
-
|
9
|
+
double(code: 500, message: "Message", body: "Response Body", parsed_response: double).as_null_object
|
10
10
|
end
|
11
11
|
|
12
12
|
before do
|
13
|
-
described_class.
|
13
|
+
allow(described_class).to receive(:get).and_return response
|
14
14
|
end
|
15
15
|
|
16
16
|
context ".call" do
|
17
17
|
|
18
|
-
before { response.
|
18
|
+
before { allow(response).to receive(:code).and_return 200 }
|
19
19
|
|
20
20
|
it "calls parsed_response" do
|
21
|
-
described_class.
|
21
|
+
expect_any_instance_of(described_class).to receive(:parsed_response)
|
22
22
|
described_class.call url
|
23
23
|
end
|
24
24
|
|
25
25
|
it "makes a call to the RTM API" do
|
26
|
-
described_class.
|
26
|
+
expect(described_class).to receive(:get).with url, format: :json
|
27
27
|
described_class.call url
|
28
28
|
end
|
29
29
|
|
@@ -33,10 +33,10 @@ module Milkman
|
|
33
33
|
|
34
34
|
context "when the response is OK (code: 200)" do
|
35
35
|
|
36
|
-
before { response.
|
36
|
+
before { allow(response).to receive(:code).and_return 200 }
|
37
37
|
|
38
38
|
it "parses the HTTParty response" do
|
39
|
-
response.
|
39
|
+
expect(response).to receive(:parsed_response)
|
40
40
|
described_class.call url
|
41
41
|
end
|
42
42
|
|
@@ -44,7 +44,7 @@ module Milkman
|
|
44
44
|
|
45
45
|
context "when the response isn't OK" do
|
46
46
|
|
47
|
-
before { described_class.
|
47
|
+
before { allow(described_class).to receive(:code).and_return 500 }
|
48
48
|
|
49
49
|
it "raises an InvalidResponseError" do
|
50
50
|
expect { described_class.call(url) }.to raise_error InvalidResponseError
|
@@ -18,13 +18,13 @@ module Milkman
|
|
18
18
|
subject { klass.sign "SECRET", parameters }
|
19
19
|
|
20
20
|
it "adds an api_sig to the specified parameters" do
|
21
|
-
parameters.
|
21
|
+
expect(parameters).not_to include(:api_sig)
|
22
22
|
expect { subject }.to change { parameters.size }.from(2).to(3)
|
23
|
-
parameters.
|
23
|
+
expect(parameters).to include(:api_sig)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "calculates a MD5 hash of the formatted shared secret and specified parameters" do
|
27
|
-
subject[:api_sig].
|
27
|
+
expect(subject[:api_sig]).to eq "e307a0ab45b29409338e21e33dd2cfca"
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -32,7 +32,7 @@ module Milkman
|
|
32
32
|
context "#format" do
|
33
33
|
|
34
34
|
it "sorts the specified parameters by key name, concatenates key value pairs and attaches it to the shared secret" do
|
35
|
-
klass.format("SECRET", parameters).
|
35
|
+
expect(klass.format("SECRET", parameters)).to eq "SECRETbazquxfoobar"
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -40,7 +40,7 @@ module Milkman
|
|
40
40
|
context "#encode" do
|
41
41
|
|
42
42
|
it "encodes the specified options to an url encoded string" do
|
43
|
-
klass.encode(foo: "bar", baz: "qux").
|
43
|
+
expect(klass.encode(foo: "bar", baz: "qux")).to eq "foo=bar&baz=qux"
|
44
44
|
end
|
45
45
|
|
46
46
|
end
|
@@ -48,7 +48,7 @@ module Milkman
|
|
48
48
|
context "#request_url" do
|
49
49
|
|
50
50
|
it "creates a request url with url encoded query parameters" do
|
51
|
-
klass.request_url(foo: "bar", baz: "qux").
|
51
|
+
expect(klass.request_url(foo: "bar", baz: "qux")).to eq "http://api.rememberthemilk.com/services/rest/?foo=bar&baz=qux"
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
@@ -56,11 +56,11 @@ module Milkman
|
|
56
56
|
context "#default_options" do
|
57
57
|
|
58
58
|
it "knows its default API permissions" do
|
59
|
-
klass.default_options[:perms].
|
59
|
+
expect(klass.default_options[:perms]).to eq "delete"
|
60
60
|
end
|
61
61
|
|
62
62
|
it "knows its default API response format" do
|
63
|
-
klass.default_options[:format].
|
63
|
+
expect(klass.default_options[:format]).to eq "json"
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
data/spec/milkman_spec.rb
CHANGED
@@ -3,11 +3,11 @@ require "spec_helper"
|
|
3
3
|
describe Milkman do
|
4
4
|
|
5
5
|
it "knows its AUTH_URL" do
|
6
|
-
Milkman::AUTH_URL.
|
6
|
+
expect(Milkman::AUTH_URL).to eq "http://www.rememberthemilk.com/services/auth/"
|
7
7
|
end
|
8
8
|
|
9
9
|
it "knows its BASE_URL" do
|
10
|
-
Milkman::BASE_URL.
|
10
|
+
expect(Milkman::BASE_URL).to eq "http://api.rememberthemilk.com/services/rest/"
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: milkman
|
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
|
- Kevin Tuhumury
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|