cdn77 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/CHANGELOG.md +5 -0
- data/README.md +4 -2
- data/lib/cdn77.rb +12 -4
- data/lib/cdn77/version.rb +1 -1
- data/spec/cdn_spec.rb +34 -25
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fb1d4de693d00f01e9e4e9bd6518a3865e96713
|
4
|
+
data.tar.gz: 3f28f5950f9050e7f46018c7eaadbef47cde752f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ac14290bfaff3a0b740fc9767b1fa4da6d956f998b649f802d27189f487ea224b9003a6dbb0036646997fd95a39b46e33ec8b9cd5e76f5e98581df0cf58f135
|
7
|
+
data.tar.gz: f1a6b8a680c3926c076aea738f818be2026415be0d9aa3758effd8fdfac10bbe345704f4d51734efa9ea5dea5754ed8a580870ede4019008d1a2cfc4a6328140
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# cdn77
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/cdn77.svg)](http://badge.fury.io/rb/cdn77)
|
4
|
+
|
3
5
|
Wrapper for CDN77 API that allows you to do a wide range of commands and tasks from an external script or server.
|
4
6
|
|
5
7
|
## Installation
|
@@ -19,7 +21,7 @@ bundle install
|
|
19
21
|
Or install it yourself as:
|
20
22
|
|
21
23
|
```bash
|
22
|
-
gem install
|
24
|
+
gem install cdn77
|
23
25
|
```
|
24
26
|
And require in irb:
|
25
27
|
|
@@ -38,7 +40,7 @@ cdn.get("account", "details")
|
|
38
40
|
# {:status => "ok", :description => "Request was successful.", :account => ...}
|
39
41
|
```
|
40
42
|
|
41
|
-
If you want to setup configuration only once you should take a look on `Cdn77.configure`. For example, it is a good idea to create initializer with following code
|
43
|
+
If you want to setup configuration only once you should take a look on `Cdn77.configure`. For example, it is a good idea to create rails initializer with following code:
|
42
44
|
|
43
45
|
```ruby
|
44
46
|
# config/initializers/cdn77.rb
|
data/lib/cdn77.rb
CHANGED
@@ -81,10 +81,18 @@ module Cdn77
|
|
81
81
|
|
82
82
|
def with_creditinals(params = {})
|
83
83
|
params ||= {}
|
84
|
-
|
85
|
-
params
|
86
|
-
|
87
|
-
|
84
|
+
result = {}
|
85
|
+
params.each do |k, v|
|
86
|
+
if v.is_a?(Array)
|
87
|
+
result["#{k.to_s}[]"] = v
|
88
|
+
else
|
89
|
+
result[k.to_s] = v
|
90
|
+
end
|
91
|
+
end
|
92
|
+
result["login"] ||= login
|
93
|
+
result["passwd"] ||= result.delete("password") if result["password"]
|
94
|
+
result["passwd"] ||= password
|
95
|
+
result
|
88
96
|
end
|
89
97
|
|
90
98
|
def raise_if_invalid(scope, method)
|
data/lib/cdn77/version.rb
CHANGED
data/spec/cdn_spec.rb
CHANGED
@@ -16,31 +16,6 @@ shared_examples "an url builder" do |method_name|
|
|
16
16
|
end
|
17
17
|
|
18
18
|
shared_examples "a request sender" do |method, url|
|
19
|
-
let (:successful_response_body) do
|
20
|
-
{
|
21
|
-
:status => "ok",
|
22
|
-
:description => "Request was successful."
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
let (:wrong_credentials_response_body) do
|
27
|
-
{
|
28
|
-
:status => "error",
|
29
|
-
:description => "Authentication failed. Please, login again or contact our support."
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
let (:wrong_parameters_response_body) do
|
34
|
-
{
|
35
|
-
:status => "error",
|
36
|
-
:description => "Request was not successful.",
|
37
|
-
:errors => {
|
38
|
-
:email => "email is required.",
|
39
|
-
:password => "password is required."
|
40
|
-
}
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
19
|
it "should raise MethodCallError when response code is not 200 OK" do
|
45
20
|
stub_request(method, url).to_return(:status => 500, :body => successful_response_body.to_json)
|
46
21
|
expect{ cdn.send(method, "account", "details") }.to raise_error(Cdn77::MethodCallError)
|
@@ -87,6 +62,32 @@ describe Cdn77::CDN do
|
|
87
62
|
end
|
88
63
|
|
89
64
|
let (:cdn) { Cdn77.cdn }
|
65
|
+
|
66
|
+
let (:successful_response_body) do
|
67
|
+
{
|
68
|
+
:status => "ok",
|
69
|
+
:description => "Request was successful."
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
let (:wrong_credentials_response_body) do
|
74
|
+
{
|
75
|
+
:status => "error",
|
76
|
+
:description => "Authentication failed. Please, login again or contact our support."
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
let (:wrong_parameters_response_body) do
|
81
|
+
{
|
82
|
+
:status => "error",
|
83
|
+
:description => "Request was not successful.",
|
84
|
+
:errors => {
|
85
|
+
:email => "email is required.",
|
86
|
+
:password => "password is required."
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
90
91
|
|
91
92
|
describe "#configuration" do
|
92
93
|
it "should return global configuration" do
|
@@ -124,6 +125,14 @@ describe Cdn77::CDN do
|
|
124
125
|
|
125
126
|
it_behaves_like "an url builder", :post
|
126
127
|
it_behaves_like "a request sender", :post, "https://client.cdn77.com/api/v2.0/account/details"
|
128
|
+
|
129
|
+
it "should encode array parameters correctly" do
|
130
|
+
stub_request(:post, "https://client.cdn77.com/api/v2.0/data/purge").
|
131
|
+
with(:body => "cdn_id=12345&url%5B%5D=public%2Fimages%2F1.png&url%5B%5D=public%2Fimages%2F2.png&login=ivan%40examle.com&passwd=secret").
|
132
|
+
to_return(:status => 200, :body => successful_response_body.to_json)
|
133
|
+
|
134
|
+
expect(cdn.post("data", "purge", :cdn_id => "12345", :url => ["public/images/1.png", "public/images/2.png"])).to eq(successful_response_body)
|
135
|
+
end
|
127
136
|
end
|
128
137
|
|
129
138
|
describe "#get" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdn77
|
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
|
- Sergey Tsvetkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".gitignore"
|
78
78
|
- ".rspec"
|
79
79
|
- ".travis.yml"
|
80
|
+
- CHANGELOG.md
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE
|
82
83
|
- README.md
|