ok_linker 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.sample +2 -0
- data/.gitignore +2 -1
- data/.rspec +4 -0
- data/.travis.yml +15 -0
- data/README.md +24 -5
- data/Rakefile +6 -0
- data/lib/ok_linker/config.rb +1 -1
- data/lib/ok_linker/error.rb +0 -1
- data/lib/ok_linker/version.rb +1 -1
- data/ok_linker.gemspec +23 -19
- data/spec/fixtures/vcr_cassettes/GetUrls.yml +51 -0
- data/spec/fixtures/vcr_cassettes/HideUrl.yml +53 -0
- data/spec/fixtures/vcr_cassettes/NonExistentMethod.yml +43 -0
- data/spec/fixtures/vcr_cassettes/RawGet.yml +51 -0
- data/spec/fixtures/vcr_cassettes/RawPost.yml +53 -0
- data/spec/fixtures/vcr_cassettes/ShortenUrl.yml +53 -0
- data/spec/fixtures/vcr_cassettes/ShortenUrlWithInvalidToken.yml +47 -0
- data/spec/fixtures/vcr_cassettes/ShortenUrlWithMissingParams.yml +45 -0
- data/spec/fixtures/vcr_cassettes/ShortenUrlWithMissingToken.yml +45 -0
- data/spec/fixtures/vcr_cassettes/UrlClicks.yml +51 -0
- data/spec/lib/ok_linker/client_spec.rb +81 -0
- data/spec/lib/ok_linker/error_spec.rb +7 -0
- data/spec/lib/ok_linker_spec.rb +29 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/vcr.rb +14 -0
- metadata +65 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ceb4ad68239f66c806a0d727f45a5c5a95388d1
|
4
|
+
data.tar.gz: 88a90f82509fea88964efc4de7636b2ff42eefd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c9ce31dc2d30d97884b17a245627dc430fddf4513a096836cd56baf84cafe3b7f31845d1c775bd3ed2817e0e722c16c542167f01aa4922c45942f5eac59416b
|
7
|
+
data.tar.gz: bcf1a69a56e9ea7752c6b1bfebbe9d8511b9679666ac9ab20dd23dc9d23536b5425af9a4d6e985e7d8e9a1ffe066e6c0097bcd76851549bdb8dabc96f25ddd61
|
data/.env.sample
ADDED
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# OkLinker
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/ok_linker)
|
4
|
+
[](https://travis-ci.org/bodrovis/ok_linker)
|
5
|
+
[](https://codeclimate.com/github/bodrovis/ok_linker)
|
6
|
+
[](https://codeclimate.com/github/bodrovis/ok_linker/coverage)
|
4
7
|
[](https://gemnasium.com/bodrovis/ok_linker)
|
5
8
|
|
6
|
-
Ruby gem to work with Odnoklassniki's URL shortening service [okey.link](http://okey.link).
|
9
|
+
Ruby gem to work with Odnoklassniki's URL shortening service [okey.link](http://okey.link). Tested against Ruby 1.9.3, 2.0, 2.1, 2.2, jRuby and rbx.
|
7
10
|
|
8
11
|
## Installation
|
9
12
|
|
@@ -25,6 +28,18 @@ to gain access.
|
|
25
28
|
After logging in, copy your API access token from the [API section](https://okey.link/cabinet/api). This token
|
26
29
|
has unlimited lifetime and has to be stored securely.
|
27
30
|
|
31
|
+
### Instantiating a Client
|
32
|
+
|
33
|
+
Create a new client by typing
|
34
|
+
|
35
|
+
client = OkLinker::Client.new(opts)
|
36
|
+
|
37
|
+
or simply with
|
38
|
+
|
39
|
+
client = OkLinker.new(opts)
|
40
|
+
|
41
|
+
You can now call OkLinker's [methods](https://github.com/bodrovis/ok_linker#calling-methods).
|
42
|
+
|
28
43
|
### Configuration
|
29
44
|
|
30
45
|
OkLinker does not require much configuration. The only thing that you need to provide is your access token.
|
@@ -53,8 +68,8 @@ clicks(url) # Get clicks statistics for the given URL
|
|
53
68
|
|
54
69
|
urls(params) # Get a list of shortened URLs.
|
55
70
|
# Allowed options:
|
56
|
-
|
57
|
-
|
71
|
+
## :epp - integer, optional. Elements per page. Default is 20.
|
72
|
+
## :page - integer, optional. Page to fetch. Default is 1.
|
58
73
|
```
|
59
74
|
|
60
75
|
Also, you can call raw methods:
|
@@ -71,9 +86,13 @@ For example,
|
|
71
86
|
|
72
87
|
These methods always return JSON or one of the errors listed [here](https://github.com/bodrovis/ok_linker/blob/master/lib/ok_linker/error.rb#L18).
|
73
88
|
|
74
|
-
##
|
89
|
+
## Testing
|
90
|
+
|
91
|
+
Rename `.env.sample` to `.env` and assign `OKEY_LINK_KEY` to your API key. This file is excluded from version control, so your token won't be exposed.
|
92
|
+
|
93
|
+
Then run
|
75
94
|
|
76
|
-
|
95
|
+
$ bundle exec rspec .
|
77
96
|
|
78
97
|
## License
|
79
98
|
|
data/Rakefile
ADDED
data/lib/ok_linker/config.rb
CHANGED
data/lib/ok_linker/error.rb
CHANGED
data/lib/ok_linker/version.rb
CHANGED
data/ok_linker.gemspec
CHANGED
@@ -1,26 +1,30 @@
|
|
1
1
|
require File.expand_path("../lib/ok_linker/version", __FILE__)
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name
|
5
|
-
spec.version
|
6
|
-
spec.authors
|
7
|
-
spec.email
|
8
|
-
spec.summary
|
9
|
-
spec.description
|
10
|
-
spec.homepage
|
11
|
-
spec.license
|
12
|
-
spec.platform
|
4
|
+
spec.name = "ok_linker"
|
5
|
+
spec.version = OkLinker::VERSION
|
6
|
+
spec.authors = ["Ilya Bodrov"]
|
7
|
+
spec.email = ["golosizpru@gmail.com"]
|
8
|
+
spec.summary = %q{Ruby gem for okey.link API.}
|
9
|
+
spec.description = %q{Ruby gem for Odnoklassniki's URL shortening service okey.link.}
|
10
|
+
spec.homepage = "https://github.com/bodrovis/ok_linker"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.platform = Gem::Platform::RUBY
|
13
13
|
|
14
|
-
spec.files
|
15
|
-
spec.test_files
|
16
|
-
spec.
|
14
|
+
spec.files = `git ls-files`.split("\n")
|
15
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
spec.extra_rdoc_files = ["README.md"]
|
17
|
+
spec.require_paths = ["lib"]
|
17
18
|
|
18
|
-
spec.
|
19
|
-
spec.
|
20
|
-
spec.
|
19
|
+
spec.add_runtime_dependency "faraday", "~> 0.9"
|
20
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 0.9"
|
21
|
+
spec.add_runtime_dependency "multi_json", "~> 1.11"
|
21
22
|
|
22
|
-
spec.add_development_dependency "rake",
|
23
|
-
spec.add_development_dependency "rspec",
|
24
|
-
spec.add_development_dependency "pry",
|
25
|
-
spec.add_development_dependency "vcr",
|
23
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
25
|
+
spec.add_development_dependency "pry", "0.10.3"
|
26
|
+
spec.add_development_dependency "vcr", "~> 3.0", ">= 3.0.0"
|
27
|
+
spec.add_development_dependency "dotenv", "~> 2.0"
|
28
|
+
spec.add_development_dependency "webmock", "~> 1.22"
|
29
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 0"
|
26
30
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://okey.link/api/v1/get-urls?epp=2&page=1
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- "<OKEY_LINK_KEY>"
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx/1.9.5
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding
|
33
|
+
Set-Cookie:
|
34
|
+
- core_cookie=3a8e4rhaDb3R4TCerMdh00bj9GGykcAL; expires=Fri, 25-Nov-2016 19:11:47
|
35
|
+
GMT; Max-Age=31536000; path=/
|
36
|
+
Cache-Control:
|
37
|
+
- no-cache
|
38
|
+
Date:
|
39
|
+
- Thu, 26 Nov 2015 19:11:47 GMT
|
40
|
+
Strict-Transport-Security:
|
41
|
+
- max-age=31536000;
|
42
|
+
Content-Security-Policy-Report-Only:
|
43
|
+
- 'default-src https:; script-src https: ''unsafe-eval'' ''unsafe-inline'';
|
44
|
+
style-src https: ''unsafe-inline''; img-src https: data:; font-src https:
|
45
|
+
data:; report-uri /csp-report'
|
46
|
+
body:
|
47
|
+
encoding: UTF-8
|
48
|
+
string: '{"result":true,"data":{"urls":[],"pages":{"current":1,"total":0,"epp":2}}}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Thu, 26 Nov 2015 19:11:40 GMT
|
51
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,53 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://okey.link/api/v1/hide-url
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: url=http%3A%2F%2Fexample.com
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- "<OKEY_LINK_KEY>"
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- nginx/1.9.5
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Vary:
|
34
|
+
- Accept-Encoding
|
35
|
+
Set-Cookie:
|
36
|
+
- core_cookie=ZPxh4809PUXXBEHPZ16mh9AdCTQatvw9; expires=Fri, 25-Nov-2016 19:07:59
|
37
|
+
GMT; Max-Age=31536000; path=/
|
38
|
+
Cache-Control:
|
39
|
+
- no-cache
|
40
|
+
Date:
|
41
|
+
- Thu, 26 Nov 2015 19:07:59 GMT
|
42
|
+
Strict-Transport-Security:
|
43
|
+
- max-age=31536000;
|
44
|
+
Content-Security-Policy-Report-Only:
|
45
|
+
- 'default-src https:; script-src https: ''unsafe-eval'' ''unsafe-inline'';
|
46
|
+
style-src https: ''unsafe-inline''; img-src https: data:; font-src https:
|
47
|
+
data:; report-uri /csp-report'
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: '{"result":true}'
|
51
|
+
http_version:
|
52
|
+
recorded_at: Thu, 26 Nov 2015 19:07:52 GMT
|
53
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://okey.link/api/v1/some-test-method
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- "<OKEY_LINK_KEY>"
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 501
|
21
|
+
message: Not Implemented
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx/1.9.5
|
25
|
+
Content-Type:
|
26
|
+
- text/plain;charset=UTF-8
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Set-Cookie:
|
32
|
+
- core_cookie=z9JY67P2UqYOzjOb3aSGTDcSmni1ly1J; expires=Fri, 25-Nov-2016 18:54:26
|
33
|
+
GMT; Max-Age=31536000; path=/
|
34
|
+
Cache-Control:
|
35
|
+
- no-cache
|
36
|
+
Date:
|
37
|
+
- Thu, 26 Nov 2015 18:54:26 GMT
|
38
|
+
body:
|
39
|
+
encoding: UTF-8
|
40
|
+
string: Method not found
|
41
|
+
http_version:
|
42
|
+
recorded_at: Thu, 26 Nov 2015 18:54:19 GMT
|
43
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://okey.link/api/v1/get-urls?epp=1
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- "<OKEY_LINK_KEY>"
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx/1.9.5
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding
|
33
|
+
Set-Cookie:
|
34
|
+
- core_cookie=8j2maHsCdFxyp4oJdqUb4bwJmmA9iawq; expires=Fri, 25-Nov-2016 18:57:34
|
35
|
+
GMT; Max-Age=31536000; path=/
|
36
|
+
Cache-Control:
|
37
|
+
- no-cache
|
38
|
+
Date:
|
39
|
+
- Thu, 26 Nov 2015 18:57:34 GMT
|
40
|
+
Strict-Transport-Security:
|
41
|
+
- max-age=31536000;
|
42
|
+
Content-Security-Policy-Report-Only:
|
43
|
+
- 'default-src https:; script-src https: ''unsafe-eval'' ''unsafe-inline'';
|
44
|
+
style-src https: ''unsafe-inline''; img-src https: data:; font-src https:
|
45
|
+
data:; report-uri /csp-report'
|
46
|
+
body:
|
47
|
+
encoding: UTF-8
|
48
|
+
string: '{"result":true,"data":{"urls":[{"url":"http:\/\/example.com","short":"http:\/\/okey.link\/529Y","clicks":0,"cpd":0}],"pages":{"current":1,"total":1,"epp":1}}}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Thu, 26 Nov 2015 18:57:26 GMT
|
51
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,53 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://okey.link/api/v1/make-short-url
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: url=http%3A%2F%2Fexample.com
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- "<OKEY_LINK_KEY>"
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- nginx/1.9.5
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Vary:
|
34
|
+
- Accept-Encoding
|
35
|
+
Set-Cookie:
|
36
|
+
- core_cookie=58APyl62mLrupKxLh4qlZN6OBDTPBrWz; expires=Fri, 25-Nov-2016 18:59:41
|
37
|
+
GMT; Max-Age=31536000; path=/
|
38
|
+
Cache-Control:
|
39
|
+
- no-cache
|
40
|
+
Date:
|
41
|
+
- Thu, 26 Nov 2015 18:59:41 GMT
|
42
|
+
Strict-Transport-Security:
|
43
|
+
- max-age=31536000;
|
44
|
+
Content-Security-Policy-Report-Only:
|
45
|
+
- 'default-src https:; script-src https: ''unsafe-eval'' ''unsafe-inline'';
|
46
|
+
style-src https: ''unsafe-inline''; img-src https: data:; font-src https:
|
47
|
+
data:; report-uri /csp-report'
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: '{"result":true,"data":{"url":"http:\/\/example.com","short":"okey.link\/52cD"}}'
|
51
|
+
http_version:
|
52
|
+
recorded_at: Thu, 26 Nov 2015 18:59:34 GMT
|
53
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,53 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://okey.link/api/v1/make-short-url
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: url=http%3A%2F%2Fexample.com
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- "<OKEY_LINK_KEY>"
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- nginx/1.9.5
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Vary:
|
34
|
+
- Accept-Encoding
|
35
|
+
Set-Cookie:
|
36
|
+
- core_cookie=9MCxjMJvbrWHL1PaZ6gULGeP5lyIsffZ; expires=Fri, 25-Nov-2016 18:21:02
|
37
|
+
GMT; Max-Age=31536000; path=/
|
38
|
+
Cache-Control:
|
39
|
+
- no-cache
|
40
|
+
Date:
|
41
|
+
- Thu, 26 Nov 2015 18:21:02 GMT
|
42
|
+
Strict-Transport-Security:
|
43
|
+
- max-age=31536000;
|
44
|
+
Content-Security-Policy-Report-Only:
|
45
|
+
- 'default-src https:; script-src https: ''unsafe-eval'' ''unsafe-inline'';
|
46
|
+
style-src https: ''unsafe-inline''; img-src https: data:; font-src https:
|
47
|
+
data:; report-uri /csp-report'
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: '{"result":true,"data":{"url":"http:\/\/example.com","short":"okey.link\/529Y"}}'
|
51
|
+
http_version:
|
52
|
+
recorded_at: Thu, 26 Nov 2015 18:20:55 GMT
|
53
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://okey.link/api/v1/make-short-url
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: url=http%3A%2F%2Fexample.com
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- '1'
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 403
|
23
|
+
message: Forbidden
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- nginx/1.9.5
|
27
|
+
Content-Type:
|
28
|
+
- text/plain;charset=UTF-8
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Vary:
|
34
|
+
- Accept-Encoding
|
35
|
+
Set-Cookie:
|
36
|
+
- core_cookie=BRHgO8xwzgniHdWqdV6qdcgab2Mq2t4M; expires=Fri, 25-Nov-2016 18:44:16
|
37
|
+
GMT; Max-Age=31536000; path=/
|
38
|
+
Cache-Control:
|
39
|
+
- no-cache
|
40
|
+
Date:
|
41
|
+
- Thu, 26 Nov 2015 18:44:16 GMT
|
42
|
+
body:
|
43
|
+
encoding: UTF-8
|
44
|
+
string: Forbidden
|
45
|
+
http_version:
|
46
|
+
recorded_at: Thu, 26 Nov 2015 18:44:09 GMT
|
47
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://okey.link/api/v1/make-short-url
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: url=
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- "<OKEY_LINK_KEY>"
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 400
|
23
|
+
message: Bad Request
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- nginx/1.9.5
|
27
|
+
Content-Type:
|
28
|
+
- text/plain;charset=UTF-8
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Set-Cookie:
|
34
|
+
- core_cookie=DMmMHJlZ4dtoYM0qERO3fRftORHPdNrR; expires=Fri, 25-Nov-2016 18:51:51
|
35
|
+
GMT; Max-Age=31536000; path=/
|
36
|
+
Cache-Control:
|
37
|
+
- no-cache
|
38
|
+
Date:
|
39
|
+
- Thu, 26 Nov 2015 18:51:51 GMT
|
40
|
+
body:
|
41
|
+
encoding: UTF-8
|
42
|
+
string: Required parameters missing.
|
43
|
+
http_version:
|
44
|
+
recorded_at: Thu, 26 Nov 2015 18:51:43 GMT
|
45
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://okey.link/api/v1/make-short-url
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: url=http%3A%2F%2Fexample.com
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- ''
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 401
|
23
|
+
message: Unauthorized
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- nginx/1.9.5
|
27
|
+
Content-Type:
|
28
|
+
- text/plain;charset=UTF-8
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Set-Cookie:
|
34
|
+
- core_cookie=M2gzVBvMGY8I4Hde0Rh0cIRSEusaixm5; expires=Fri, 25-Nov-2016 18:53:10
|
35
|
+
GMT; Max-Age=31536000; path=/
|
36
|
+
Cache-Control:
|
37
|
+
- no-cache
|
38
|
+
Date:
|
39
|
+
- Thu, 26 Nov 2015 18:53:10 GMT
|
40
|
+
body:
|
41
|
+
encoding: UTF-8
|
42
|
+
string: Authorization required
|
43
|
+
http_version:
|
44
|
+
recorded_at: Thu, 26 Nov 2015 18:53:03 GMT
|
45
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://okey.link/api/v1/get-url-clicks?url=http://example.com
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- ok_linker ruby gem/0.1.0
|
14
|
+
Access-Token:
|
15
|
+
- "<OKEY_LINK_KEY>"
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx/1.9.5
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding
|
33
|
+
Set-Cookie:
|
34
|
+
- core_cookie=fRJyH4BnrK4R386esDrQFjEbnx7P2oAc; expires=Fri, 25-Nov-2016 19:09:38
|
35
|
+
GMT; Max-Age=31536000; path=/
|
36
|
+
Cache-Control:
|
37
|
+
- no-cache
|
38
|
+
Date:
|
39
|
+
- Thu, 26 Nov 2015 19:09:38 GMT
|
40
|
+
Strict-Transport-Security:
|
41
|
+
- max-age=31536000;
|
42
|
+
Content-Security-Policy-Report-Only:
|
43
|
+
- 'default-src https:; script-src https: ''unsafe-eval'' ''unsafe-inline'';
|
44
|
+
style-src https: ''unsafe-inline''; img-src https: data:; font-src https:
|
45
|
+
data:; report-uri /csp-report'
|
46
|
+
body:
|
47
|
+
encoding: UTF-8
|
48
|
+
string: '{"result":true,"data":{"url":"http:\/\/example.com","short":"http:\/\/okey.link\/4dyj","clicks":0,"cpd":0}}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Thu, 26 Nov 2015 19:09:31 GMT
|
51
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,81 @@
|
|
1
|
+
RSpec.describe OkLinker::Client do
|
2
|
+
let(:full_url) { 'http://example.com' }
|
3
|
+
|
4
|
+
specify "#shorten" do
|
5
|
+
response = VCR.use_cassette("ShortenUrl") do
|
6
|
+
test_client.shorten(full_url)
|
7
|
+
end
|
8
|
+
expect(response['data']['url']).to eq full_url
|
9
|
+
expect(response['data']['short']).not_to be_empty
|
10
|
+
expect(response['result']).to be true
|
11
|
+
end
|
12
|
+
|
13
|
+
specify "#get" do
|
14
|
+
response = VCR.use_cassette("RawGet") do
|
15
|
+
test_client.get('get-urls', epp: 1)
|
16
|
+
end
|
17
|
+
expect(response['result']).to be true
|
18
|
+
expect(response['data']['pages']['epp']).to eq 1
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "#post" do
|
22
|
+
response = VCR.use_cassette("RawPost") do
|
23
|
+
test_client.post('make-short-url', url: full_url)
|
24
|
+
end
|
25
|
+
expect(response['data']['url']).to eq full_url
|
26
|
+
expect(response['data']['short']).not_to be_empty
|
27
|
+
expect(response['result']).to be true
|
28
|
+
end
|
29
|
+
|
30
|
+
specify "#hide" do
|
31
|
+
response = VCR.use_cassette("HideUrl") do
|
32
|
+
test_client.hide(full_url)
|
33
|
+
end
|
34
|
+
expect(response['result']).to be true
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "#clicks" do
|
38
|
+
response = VCR.use_cassette("UrlClicks") do
|
39
|
+
test_client.clicks(full_url)
|
40
|
+
end
|
41
|
+
expect(response['result']).to be true
|
42
|
+
expect(response['data']['url']).to eq full_url
|
43
|
+
expect(response['data']['clicks']).to eq 0
|
44
|
+
expect(response['data']['cpd']).to eq 0
|
45
|
+
end
|
46
|
+
|
47
|
+
specify "#urls" do
|
48
|
+
response = VCR.use_cassette("GetUrls") do
|
49
|
+
test_client.urls(page: 1, epp: 2)
|
50
|
+
end
|
51
|
+
expect(response['result']).to be true
|
52
|
+
expect(response['data']['pages']['current']).to eq 1
|
53
|
+
expect(response['data']['pages']['epp']).to eq 2
|
54
|
+
end
|
55
|
+
|
56
|
+
context "errors" do
|
57
|
+
it "should raise OkLinker::Error::Forbidden if access token is not valid" do
|
58
|
+
VCR.use_cassette("ShortenUrlWithInvalidToken") do
|
59
|
+
expect { test_client('1').shorten(full_url) }.to raise_error(OkLinker::Error::Forbidden)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise OkLinker::Error::BadRequest if required attributes are not provided" do
|
64
|
+
VCR.use_cassette("ShortenUrlWithMissingParams") do
|
65
|
+
expect { test_client.shorten('') }.to raise_error(OkLinker::Error::BadRequest)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should raise OkLinker::Error::Unauthorized if access_token is not provided" do
|
70
|
+
VCR.use_cassette("ShortenUrlWithMissingToken") do
|
71
|
+
expect { test_client('').shorten(full_url) }.to raise_error(OkLinker::Error::Unauthorized)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise OkLinker::Error::NotImplemented if non-existent method is requested" do
|
76
|
+
VCR.use_cassette("NonExistentMethod") do
|
77
|
+
expect { test_client.get('some-test-method') }.to raise_error(OkLinker::Error::NotImplemented)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec.describe OkLinker do
|
2
|
+
specify ".new" do
|
3
|
+
client = OkLinker.new
|
4
|
+
expect(client).to be_an_instance_of OkLinker::Client
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "configuration" do
|
8
|
+
let(:access_token) {SecureRandom.hex}
|
9
|
+
it "accepts config options" do
|
10
|
+
OkLinker.configure do |c|
|
11
|
+
c.access_token = access_token
|
12
|
+
end
|
13
|
+
expect(OkLinker.options[:access_token]).to eq access_token
|
14
|
+
end
|
15
|
+
|
16
|
+
it "accepts config options when creating client" do
|
17
|
+
client = OkLinker::Client.new(access_token: access_token)
|
18
|
+
expect(client.instance_variable_get('@access_token')).to eq access_token
|
19
|
+
end
|
20
|
+
|
21
|
+
it "is possible to pass config block to OkLinker.config" do
|
22
|
+
config = OkLinker::Config.configure do |c|
|
23
|
+
c.access_token = access_token
|
24
|
+
end
|
25
|
+
OkLinker.config = config
|
26
|
+
expect(OkLinker.config).to eq config
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'dotenv'
|
5
|
+
require 'pry'
|
6
|
+
Dotenv.load
|
7
|
+
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
9
|
+
require 'ok_linker'
|
10
|
+
|
11
|
+
module SpecHelper
|
12
|
+
def test_client(access_token = nil)
|
13
|
+
return if @client && !access_token
|
14
|
+
|
15
|
+
@client = OkLinker::Client.new(access_token: access_token || ENV.fetch("OKEY_LINK_KEY"))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.include SpecHelper
|
21
|
+
end
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
|
3
|
+
VCR.configure do |c|
|
4
|
+
c.ignore_hosts "codeclimate.com"
|
5
|
+
c.allow_http_connections_when_no_cassette = true
|
6
|
+
c.hook_into :webmock
|
7
|
+
c.cassette_library_dir = File.join(File.dirname(__FILE__), "..", "fixtures", "vcr_cassettes")
|
8
|
+
c.configure_rspec_metadata!
|
9
|
+
c.filter_sensitive_data("<OKEY_LINK_KEY>") { ENV.fetch("OKEY_LINK_KEY") }
|
10
|
+
|
11
|
+
c.before_record do |i|
|
12
|
+
i.response.body.force_encoding("UTF-8")
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ok_linker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Bodrov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -114,17 +114,64 @@ dependencies:
|
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: 3.0.0
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: dotenv
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '2.0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '2.0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: webmock
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.22'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '1.22'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: codeclimate-test-reporter
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
117
159
|
description: Ruby gem for Odnoklassniki's URL shortening service okey.link.
|
118
160
|
email:
|
119
161
|
- golosizpru@gmail.com
|
120
162
|
executables: []
|
121
163
|
extensions: []
|
122
|
-
extra_rdoc_files:
|
164
|
+
extra_rdoc_files:
|
165
|
+
- README.md
|
123
166
|
files:
|
167
|
+
- ".env.sample"
|
124
168
|
- ".gitignore"
|
169
|
+
- ".rspec"
|
170
|
+
- ".travis.yml"
|
125
171
|
- Gemfile
|
126
172
|
- LICENSE
|
127
173
|
- README.md
|
174
|
+
- Rakefile
|
128
175
|
- lib/ok_linker.rb
|
129
176
|
- lib/ok_linker/client.rb
|
130
177
|
- lib/ok_linker/config.rb
|
@@ -133,6 +180,21 @@ files:
|
|
133
180
|
- lib/ok_linker/request.rb
|
134
181
|
- lib/ok_linker/version.rb
|
135
182
|
- ok_linker.gemspec
|
183
|
+
- spec/fixtures/vcr_cassettes/GetUrls.yml
|
184
|
+
- spec/fixtures/vcr_cassettes/HideUrl.yml
|
185
|
+
- spec/fixtures/vcr_cassettes/NonExistentMethod.yml
|
186
|
+
- spec/fixtures/vcr_cassettes/RawGet.yml
|
187
|
+
- spec/fixtures/vcr_cassettes/RawPost.yml
|
188
|
+
- spec/fixtures/vcr_cassettes/ShortenUrl.yml
|
189
|
+
- spec/fixtures/vcr_cassettes/ShortenUrlWithInvalidToken.yml
|
190
|
+
- spec/fixtures/vcr_cassettes/ShortenUrlWithMissingParams.yml
|
191
|
+
- spec/fixtures/vcr_cassettes/ShortenUrlWithMissingToken.yml
|
192
|
+
- spec/fixtures/vcr_cassettes/UrlClicks.yml
|
193
|
+
- spec/lib/ok_linker/client_spec.rb
|
194
|
+
- spec/lib/ok_linker/error_spec.rb
|
195
|
+
- spec/lib/ok_linker_spec.rb
|
196
|
+
- spec/spec_helper.rb
|
197
|
+
- spec/support/vcr.rb
|
136
198
|
homepage: https://github.com/bodrovis/ok_linker
|
137
199
|
licenses:
|
138
200
|
- MIT
|