bocu 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2cda24473af47b1835505dbdd4b56b7df8ff6cc
4
+ data.tar.gz: 34c09ea55b27719089d6b59c2889345f0f1c8a3e
5
+ SHA512:
6
+ metadata.gz: 6fb3771d6242d02604b49e517558a5646df2ebc1224cc3a2091bc48529c6d871dd556bb143b23b495b9c41c3c487fe2cfe8a71edf91ec44c652f49ee28fe9488
7
+ data.tar.gz: '0719772c9a9b4967c51572ac29f803f4acc8a878b759c39fad612c6d80bb6a06d98923a287f2d87a288b4549e51205171c0bc79af0aaf0c1a0467c6cdebf870b'
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,35 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - '.bundle/**/*'
5
+ - 'bin/**/*'
6
+ - 'config/**/*'
7
+ - 'db/**/*'
8
+ - 'lib/tasks/**/*'
9
+ - 'app/controllers/users/confirmations_controller.rb'
10
+ - 'app/controllers/users/registrations_controller.rb'
11
+ - 'lib/extensions/simple_form/inputs/array_input.rb'
12
+ - 'vendor/assets/**/**/*'
13
+ - 'spec/factories/**/*'
14
+
15
+ Documentation:
16
+ Enabled: false
17
+
18
+ Metrics/LineLength:
19
+ Max: 110
20
+
21
+ Style/SymbolArray:
22
+ Enabled: true
23
+
24
+ Style/FrozenStringLiteralComment:
25
+ Enabled: false
26
+
27
+ Style/RedundantFreeze:
28
+ Enabled: false
29
+
30
+ Metrics/AbcSize:
31
+ Exclude:
32
+ - 'test/**/*'
33
+
34
+ Lint/AmbiguousBlockAssociation:
35
+ Enabled: false
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.1
4
+ before_install: gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bocu.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Emil Shakirov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,102 @@
1
+ # Bocu
2
+ ![](https://lh6.ggpht.com/FEPLCErGsrB4ErBdbtKaZfDq6df3Od2-g0kA8soEi3TdiuSYAhqSn4I87IYs1blzpd0=w300)
3
+
4
+ [![Build Status](https://travis-ci.org/vaihtovirta/bocu.svg?branch=master)](https://travis-ci.org/vaihtovirta/bocu)
5
+
6
+ API wrapper for [Coub](http://coub.com)
7
+
8
+ Powered by [Her](https://github.com/remiprev/her) — ORM for REST API.
9
+
10
+ Currently under development, so it supports only several public API methods.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'bocu'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ You can check official Coub API docs [here](http://coub.com/dev/docs/Coub+API/Overview).
23
+
24
+ ##### Search by query:
25
+
26
+ ```ruby
27
+ require 'bocu'
28
+
29
+ coubs = Bocu::Coub.search('optimism')
30
+ coubs = coubs.order_by(:likes_count).page(5).per(25).fetch
31
+ # returns array of coubs, wrapped with Her::Model
32
+
33
+ coubs.first.attributes
34
+ # => returns Big Coub JSON, most part is omitted
35
+ # => {"flag"=>nil, "abuses"=>nil, "recoubs_by_users_channels"=>nil,
36
+ # "recoub"=>nil, "like"=>nil, "in_my_best2015"=>false,
37
+ # "type"=>"Coub::Simple", "permalink"=>"5kirj"...
38
+ ```
39
+
40
+ ##### Search by id:
41
+
42
+ ```ruby
43
+ require 'bocu'
44
+
45
+ coub = Bocu::Coub.find('70x8c')
46
+ # => returns Big Coub JSON, most part is omitted
47
+ # => #<Bocu::Coub(coubs/12553778) flag=nil abuses=nil recoubs_by_users_channels=nil recoub=nil like=nil
48
+ # in_my_best2015=false type="Coub::Simple" permalink="70x8c" title="House Every Weekend"
49
+ # visibility_type="public" original_visibility_type="public" channel_id=1162114
50
+ # created_at="2015-06-26T04:24:28Z" updated_at="2017-07-10T03:56:43Z" ...
51
+ ```
52
+
53
+ ##### Timeline:
54
+
55
+ [Related docs](https://coub.com/dev/docs/Coub+API/Timelines)
56
+
57
+ ```ruby
58
+ require 'bocu'
59
+
60
+ Bocu::Coub.by_tag('games').fetch # coubs by tag
61
+ Bocu::Coub.hot.fetch # timeline of the Hot section
62
+
63
+ # timeline of the Explore section categories
64
+ Bocu::Coub.random.fetch
65
+ Bocu::Coub.newest.fetch
66
+ Bocu::Coub.coub_of_the_day.fetch
67
+ ```
68
+
69
+ ##### Using chainable scopes for pagination and ordering:
70
+
71
+ ```ruby
72
+ require 'bocu'
73
+
74
+ coubs = Bocu::Coub.search('drive')
75
+ coubs = coubs.order_by(:views_count).per_page(5).page(2)
76
+
77
+ result = coubs.fetch # Returns array of 5 hot coubs starting from page 2
78
+ result.metadata # {:page=>"2", :total_pages=>504, :per_page=>"5"}
79
+ result.count # 5
80
+ ```
81
+
82
+ ## TODO
83
+
84
+ - Improve documentaion
85
+ - More tests
86
+ - More supported methods
87
+ - Authentication(?)
88
+
89
+ ## Development
90
+
91
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vaihtovirta/bocu.
98
+
99
+
100
+ ## License
101
+
102
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'bocu/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'bocu'
9
+ spec.version = Bocu::VERSION
10
+ spec.authors = ['Emil Shakirov']
11
+ spec.email = ['5o.smoker@gmail.com']
12
+
13
+ spec.summary = 'Ruby wrapper for coub.com API'
14
+ spec.description = 'Ruby wrapper for coub.com API'
15
+ spec.homepage = 'https://github.com/vaihtovirta/bocu'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
19
+ # delete this section to allow pushing this gem to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.14'
32
+ spec.add_development_dependency 'minitest-vcr', '~> 1.4'
33
+ spec.add_development_dependency 'minitest', '~> 5.10'
34
+ spec.add_development_dependency 'pry', '~> 0.10'
35
+ spec.add_development_dependency 'rake', '~> 12'
36
+ spec.add_development_dependency 'vcr', '~> 3'
37
+ spec.add_development_dependency 'webmock', '~> 3'
38
+ spec.add_development_dependency 'simplecov', '~> 0.10'
39
+
40
+ spec.add_runtime_dependency 'her', '~> 0.9'
41
+ end
@@ -0,0 +1,9 @@
1
+ require 'bocu/configuration'
2
+ require 'bocu/version'
3
+
4
+ module Bocu
5
+ SEARCH_ENDPOINT = 'search'.freeze
6
+ TIMELINE_ENDPOINT = 'timeline'.freeze
7
+
8
+ extend Bocu::Configuration
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'active_support/concern'
2
+
3
+ module Bocu
4
+ module CommonScopes
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ scope :order_by, ->(order_by) { where(order_by: order_by) }
9
+ scope :page_of, ->(order_by) { where(page_of: order_by) }
10
+ scope :page, ->(page_number) { where(page: page_number) }
11
+ scope :per_page, ->(per_page_quantity) { where(per_page: per_page_quantity) }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ require 'her'
2
+ require 'bocu/middleware/parser'
3
+ require 'bocu/concerns/common_scopes'
4
+
5
+ module Bocu
6
+ module Configuration
7
+ DEFAULT_ENDPOINT = 'http://coub.com/api/v2'.freeze
8
+
9
+ class << self
10
+ def extended(_mod)
11
+ configure
12
+ end
13
+
14
+ def configure
15
+ setup_her
16
+ require_models
17
+ end
18
+
19
+ private
20
+
21
+ def require_models
22
+ require 'bocu/timelines/explore'
23
+ require 'bocu/timelines/hot'
24
+ require 'bocu/timelines/tag'
25
+ require 'bocu/coub'
26
+ require 'bocu/search'
27
+ end
28
+
29
+ def setup_her
30
+ Her::API.setup url: DEFAULT_ENDPOINT do |connection|
31
+ connection.use Faraday::Request::UrlEncoded
32
+ connection.use Bocu::Middleware::Parser
33
+ connection.use Faraday::Adapter::NetHttp
34
+ connection.use Faraday::Response::Logger
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ module Bocu
2
+ class Coub
3
+ include Her::Model
4
+ include CommonScopes
5
+
6
+ class << self
7
+ def search(query)
8
+ Search.with_query(query)
9
+ end
10
+
11
+ def by_tag(tag_name)
12
+ Bocu::Timelines::Tag.by_tag(tag_name)
13
+ end
14
+
15
+ def hot
16
+ Bocu::Timelines::Hot.all
17
+ end
18
+
19
+ # definition of coub_of_the_day, newest, random methods
20
+ Bocu::Timelines::Explore::CATEGORIES.each do |category|
21
+ define_method category do
22
+ Timelines::Explore.send(category)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ module Bocu
2
+ module Middleware
3
+ class Parser < Faraday::Response::Middleware
4
+ DATA_KEYS = %i[coubs channels].freeze
5
+
6
+ def on_complete(env)
7
+ env[:body] = parse(env[:body])
8
+ end
9
+
10
+ private
11
+
12
+ def includes_data_keys?(json)
13
+ (json.keys & DATA_KEYS).any?
14
+ end
15
+
16
+ def parse(body)
17
+ json = parsed_json(body)
18
+ metadata = json.slice!(*DATA_KEYS) if includes_data_keys?(json)
19
+
20
+ { data: json, metadata: metadata || {} }
21
+ end
22
+
23
+ def parsed_json(body)
24
+ MultiJson.load(body, symbolize_keys: true)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ module Bocu
2
+ class Search
3
+ include Her::Model
4
+ include CommonScopes
5
+
6
+ collection_path Bocu::SEARCH_ENDPOINT
7
+ parse_root_in_json :coubs, format: :active_model_serializers
8
+
9
+ scope :with_query, ->(query) { where(q: query) }
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Bocu
2
+ module Timelines
3
+ class Explore
4
+ include Her::Model
5
+ include CommonScopes
6
+
7
+ CATEGORIES = %i[coub_of_the_day newest random].freeze
8
+
9
+ collection_path "#{Bocu::TIMELINE_ENDPOINT}/explore/:category_id"
10
+ parse_root_in_json :coubs, format: :active_model_serializers
11
+
12
+ CATEGORIES.each { |category| scope category, -> { where(category_id: category) } }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Bocu
2
+ module Timelines
3
+ class Hot
4
+ include Her::Model
5
+ include CommonScopes
6
+
7
+ collection_path "#{Bocu::TIMELINE_ENDPOINT}/hot"
8
+ parse_root_in_json :coubs, format: :active_model_serializers
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Bocu
2
+ module Timelines
3
+ class Tag
4
+ include Her::Model
5
+ include CommonScopes
6
+
7
+ collection_path "#{Bocu::TIMELINE_ENDPOINT}/tag/:tag_name"
8
+ parse_root_in_json :coubs, format: :active_model_serializers
9
+
10
+ scope :by_tag, ->(tag_name) { where(tag_name: tag_name) }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Bocu
2
+ VERSION = '0.3.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bocu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Emil Shakirov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-04 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.10'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.10'
125
+ - !ruby/object:Gem::Dependency
126
+ name: her
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ description: Ruby wrapper for coub.com API
140
+ email:
141
+ - 5o.smoker@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rubocop.yml"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - bocu.gemspec
154
+ - lib/bocu.rb
155
+ - lib/bocu/concerns/common_scopes.rb
156
+ - lib/bocu/configuration.rb
157
+ - lib/bocu/coub.rb
158
+ - lib/bocu/middleware/parser.rb
159
+ - lib/bocu/search.rb
160
+ - lib/bocu/timelines/explore.rb
161
+ - lib/bocu/timelines/hot.rb
162
+ - lib/bocu/timelines/tag.rb
163
+ - lib/bocu/version.rb
164
+ homepage: https://github.com/vaihtovirta/bocu
165
+ licenses:
166
+ - MIT
167
+ metadata:
168
+ allowed_push_host: https://rubygems.org
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.6.11
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Ruby wrapper for coub.com API
189
+ test_files: []