coub_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -0
- data/Rakefile +7 -0
- data/coub_api.gemspec +28 -0
- data/lib/coub_api.rb +78 -0
- data/lib/coub_api/version.rb +3 -0
- data/spec/lib/coub_api_spec.rb +28 -0
- data/spec/spec_helper.rb +1 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3bf86a06ade4e795511b94eca92a7d6771c735c4
|
4
|
+
data.tar.gz: fa7e36138d3dcb7fcdece6a711bad8693652ec34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 611fe71f949df2726b2818c9193987e6e8698e6ea0598bca1cca5feb0265d6f3fa8eb384d56041c37e4dea1cf2183c4097d5cebc138da20441a29fcd73b069bb
|
7
|
+
data.tar.gz: 003a1245d027a4b602d982b0a2c12147ebdeddcbaab80a54ebe5e2832a1c91f0112e1bdc358d0753eb2f06017bf6393cff45439b51d7075cad63e6806b432dbf
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
coub_api (0.0.1)
|
5
|
+
faraday (~> 0.8)
|
6
|
+
hashie
|
7
|
+
multi_json (~> 1.3)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
faraday (0.9.1)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
hashie (3.4.2)
|
16
|
+
multi_json (1.11.2)
|
17
|
+
multipart-post (2.0.0)
|
18
|
+
rake (10.4.2)
|
19
|
+
rspec (3.3.0)
|
20
|
+
rspec-core (~> 3.3.0)
|
21
|
+
rspec-expectations (~> 3.3.0)
|
22
|
+
rspec-mocks (~> 3.3.0)
|
23
|
+
rspec-core (3.3.2)
|
24
|
+
rspec-support (~> 3.3.0)
|
25
|
+
rspec-expectations (3.3.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.3.0)
|
28
|
+
rspec-mocks (3.3.2)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.3.0)
|
31
|
+
rspec-support (3.3.0)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler (~> 1.3)
|
38
|
+
coub_api!
|
39
|
+
rake
|
40
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Peter Savichev (proton)
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# CoubApi gem
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
gem install coub_api
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
api = CoubApi::Client.new
|
10
|
+
r = api.get(:search, q: 'test')
|
11
|
+
r = api.search(q: 'test')
|
12
|
+
r = api.search(q: 'test', api_version: 1)
|
13
|
+
|
14
|
+
oauth_url = CoubApi.authorization_url(client_id: CLIENT_ID, redirect_uri: URI)
|
15
|
+
oauth_url = CoubApi.authorization_url(client_id: CLIENT_ID, redirect_uri: URI, scope: %i[like repost])
|
16
|
+
|
17
|
+
api = CoubApi::Client.new(ACCESS_TOKEN, api_version: 2)
|
18
|
+
api = CoubApi::Client.new(ACCESS_TOKEN)
|
19
|
+
|
20
|
+
r = api.get('likes/by_channel', channel_id: 1164719)
|
21
|
+
r = api.get(:likes, :by_channel, channel_id: 1164719)
|
22
|
+
r = api.get(:likes, :by_channel, channel_id: 1164719, access_token: ANOTHER_ACCESS_TOKEN)
|
data/Rakefile
ADDED
data/coub_api.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coub_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coub_api"
|
8
|
+
spec.version = CoubApi::VERSION
|
9
|
+
spec.authors = ["Peter Savichev (proton)"]
|
10
|
+
spec.email = ["psavichev@gmail.com"]
|
11
|
+
spec.description = "Ruby wrapper for Coub API."
|
12
|
+
spec.summary = "Ruby wrapper for Coub API."
|
13
|
+
spec.homepage = "https://github.com/proton/coub_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "faraday", "~> 0.8"
|
26
|
+
spec.add_runtime_dependency "multi_json", "~> 1.3"
|
27
|
+
spec.add_runtime_dependency "hashie"
|
28
|
+
end
|
data/lib/coub_api.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'coub_api/version'
|
2
|
+
|
3
|
+
require 'multi_json'
|
4
|
+
require 'faraday'
|
5
|
+
|
6
|
+
module CoubApi
|
7
|
+
API_URL = 'http://coub.com/api'
|
8
|
+
API_VERSION = 2
|
9
|
+
AUTH_URL = 'http://coub.com/oauth/authorize'
|
10
|
+
|
11
|
+
def self.authorization_url(client_id:, redirect_uri:, scope: [])
|
12
|
+
opts = {response_type: :code}
|
13
|
+
opts[:client_id] = client_id
|
14
|
+
opts[:redirect_uri] = redirect_uri
|
15
|
+
opts[:scope] = scope.join('+') unless scope.empty?
|
16
|
+
|
17
|
+
"#{AUTH_URL}?#{opts.map{|k,v| "#{k}=#{v}"}.join('&')}"
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
class Error < StandardError
|
22
|
+
attr_reader :data
|
23
|
+
|
24
|
+
def error_msg
|
25
|
+
@data['error']
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(data)
|
29
|
+
@data = data
|
30
|
+
super(error_msg)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Client
|
35
|
+
def initialize(access_token = nil, api_version: API_VERSION)
|
36
|
+
@access_token = access_token
|
37
|
+
@api_version = api_version
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :security_options, :request_options, :response, :connection
|
41
|
+
|
42
|
+
def make_request(method, http_method, request_params = {})
|
43
|
+
api_version = request_params.delete(:api_version) || @api_version
|
44
|
+
url = "#{CoubApi::API_URL}/v#{api_version}/#{method}.json"
|
45
|
+
|
46
|
+
faraday_options = {request: {timeout: 150, open_timeout: 150}, url: url}
|
47
|
+
connection = Faraday.new(faraday_options) do |faraday|
|
48
|
+
faraday.headers['Content-Type'] = 'application/json'
|
49
|
+
faraday.request :url_encoded
|
50
|
+
faraday.response :logger
|
51
|
+
faraday.adapter Faraday.default_adapter
|
52
|
+
end
|
53
|
+
|
54
|
+
request_params[:access_token] = @access_token if @access_token
|
55
|
+
response = connection.send(http_method) do |request|
|
56
|
+
request.params = request_params
|
57
|
+
end
|
58
|
+
|
59
|
+
json_data = MultiJson.load(response.body)
|
60
|
+
if json_data.is_a? Hash
|
61
|
+
raise Error, json_data if json_data['error']
|
62
|
+
end
|
63
|
+
json_data
|
64
|
+
end
|
65
|
+
|
66
|
+
def get(*methods, **hargs)
|
67
|
+
make_request(methods.join('/'), __method__, **hargs)
|
68
|
+
end
|
69
|
+
|
70
|
+
def post(*methods, **hargs)
|
71
|
+
make_request(methods.join('/'), __method__, **hargs)
|
72
|
+
end
|
73
|
+
|
74
|
+
def method_missing(name, **hargs)
|
75
|
+
get(name, **hargs)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CoubApi do
|
4
|
+
it "should return right authorization_url" do
|
5
|
+
expect(CoubApi.authorization_url(client_id: 'CLIENT_ID', redirect_uri: 'http://localhost', scope: %i[like repost])).to eq('http://coub.com/oauth/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=http://localhost&scope=like+repost')
|
6
|
+
expect(CoubApi.authorization_url(client_id: 'CLIENT_ID', redirect_uri: 'URI')).to eq('http://coub.com/oauth/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=URI')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return error on empty search request" do
|
10
|
+
api = CoubApi::Client.new
|
11
|
+
expect { api.get(:search) }.to raise_error CoubApi::Error
|
12
|
+
expect { api.search }.to raise_error CoubApi::Error
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return search result" do
|
16
|
+
api = CoubApi::Client.new
|
17
|
+
|
18
|
+
r = api.get(:search, q: 'test')
|
19
|
+
expect(r).to be_a(Hash)
|
20
|
+
expect(r).to include('coubs')
|
21
|
+
expect(r).to include('total_pages')
|
22
|
+
|
23
|
+
r = api.search(q: 'test')
|
24
|
+
expect(r).to be_a(Hash)
|
25
|
+
expect(r).to include('coubs')
|
26
|
+
expect(r).to include('total_pages')
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'coub_api'
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coub_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Savichev (proton)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: multi_json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: hashie
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Ruby wrapper for Coub API.
|
98
|
+
email:
|
99
|
+
- psavichev@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- coub_api.gemspec
|
111
|
+
- lib/coub_api.rb
|
112
|
+
- lib/coub_api/version.rb
|
113
|
+
- spec/lib/coub_api_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
homepage: https://github.com/proton/coub_api
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.1
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Ruby wrapper for Coub API.
|
139
|
+
test_files:
|
140
|
+
- spec/lib/coub_api_spec.rb
|
141
|
+
- spec/spec_helper.rb
|