yo4r 0.1.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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +19 -0
- data/lib/yo4r.rb +4 -0
- data/lib/yo4r/client.rb +19 -0
- data/lib/yo4r/errors.rb +4 -0
- data/lib/yo4r/http.rb +33 -0
- data/lib/yo4r/version.rb +3 -0
- data/spec/client_spec.rb +83 -0
- data/spec/spec_helper.rb +11 -0
- data/yo4r.gemspec +26 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ff18458f2d2b26e75481e6ab10d5b03db40dd05b
|
4
|
+
data.tar.gz: 48c77da3433d9ecf03620f535c43b1f3a5e321fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8aa57a37f6eb184688c74a8c9b0da4ea8cb98942de86ce4bac7026350530439fe1e33bdcfa4737c1a33fd559c9120c42cd0a561e0a72ed31ab5bff8e07802a2
|
7
|
+
data.tar.gz: 741d55c399a7db23484ba8b811fdee7bf47401ba8883ff62d4857fb2c1037a229420e9fb0e73ba943e7e51b84e8d7ea08a7e239852eca5aa2e09ae9022479331
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tsukuru Tanimichi
|
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,41 @@
|
|
1
|
+
# yo4r
|
2
|
+
A Ruby interface to the Yo API.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Install the gem with:
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install yo4r
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
At first, get the API token at http://developer.justyo.co/ and then:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'yo4r'
|
16
|
+
|
17
|
+
# create a client
|
18
|
+
client = Yo::Client.new(api_token: 'your_api_token')
|
19
|
+
|
20
|
+
# Yo to someone
|
21
|
+
client.yo(username: 'someone')
|
22
|
+
|
23
|
+
# Yo to all subscribers
|
24
|
+
client.yoall
|
25
|
+
|
26
|
+
# count the number of your subscribers
|
27
|
+
client.subscribers_count # => 42
|
28
|
+
```
|
29
|
+
|
30
|
+
That's all.
|
31
|
+
|
32
|
+
## Exceptions
|
33
|
+
- If `Yo::ClientError` is raised, the API token or username maybe invalid.
|
34
|
+
- If `Yo::UnknownError` is raised, the Yo API server maybe down.
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
1. Fork it ( https://github.com/tanimichi/yo4r/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require 'unindent'
|
4
|
+
|
5
|
+
if ENV['YO_API_TOKEN'] and ENV['YO_USER_NAME']
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
else
|
8
|
+
task :spec do
|
9
|
+
puts <<-EOS.unindent
|
10
|
+
In the case of this gem, I think testing with stubbing network access has no meaning!
|
11
|
+
At first, execute
|
12
|
+
export YO_USER_NAME='your_yo_username'
|
13
|
+
export YO_API_TOKEN='your_yo_api_token'
|
14
|
+
and then, execute `bundle exec rake spec` again!
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :spec
|
data/lib/yo4r.rb
ADDED
data/lib/yo4r/client.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Yo
|
2
|
+
class Client
|
3
|
+
def initialize(api_token: '')
|
4
|
+
@http = HTTP.new(api_token: api_token)
|
5
|
+
end
|
6
|
+
|
7
|
+
def yo(username: '')
|
8
|
+
@http.yo(username: username)
|
9
|
+
end
|
10
|
+
|
11
|
+
def yoall
|
12
|
+
@http.yoall
|
13
|
+
end
|
14
|
+
|
15
|
+
def subscribers_count
|
16
|
+
@http.subscribers_count
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/yo4r/errors.rb
ADDED
data/lib/yo4r/http.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Yo
|
5
|
+
class HTTP
|
6
|
+
def initialize(api_token: nil)
|
7
|
+
@api_token = api_token
|
8
|
+
@faraday = Faraday.new('http://api.justyo.co')
|
9
|
+
end
|
10
|
+
|
11
|
+
def yo(username: nil)
|
12
|
+
return true if access_api { @faraday.post('/yo/', api_token: @api_token, username: username) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def yoall
|
16
|
+
access_api { @faraday.post('/yoall/', api_token: @api_token) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def subscribers_count
|
20
|
+
access_api { @faraday.get('/subscribers_count/', api_token: @api_token) }
|
21
|
+
end
|
22
|
+
|
23
|
+
private def access_api
|
24
|
+
begin
|
25
|
+
params = JSON.parse(yield.body)
|
26
|
+
rescue Exception => e
|
27
|
+
raise UnknownError, e.message
|
28
|
+
end
|
29
|
+
raise ClientError, params['error'] if params['error']
|
30
|
+
params['result']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/yo4r/version.rb
ADDED
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yo::Client do
|
4
|
+
describe '#yo' do
|
5
|
+
context "with the valid api token" do
|
6
|
+
subject { Yo::Client.new(api_token: ENV['YO_API_TOKEN']) }
|
7
|
+
context "with the valid username" do
|
8
|
+
it "returns true" do
|
9
|
+
subject.yo(username: ENV['YO_USER_NAME']).should eq(true)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with an invalid username' do
|
14
|
+
it 'raise Yo::ClientError' do
|
15
|
+
->{ subject.yo(username: 'invalid_user_name') }.should raise_error(Yo::ClientError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with an invalid api token' do
|
21
|
+
subject { Yo::Client.new(api_token: 'invalid_api_token') }
|
22
|
+
it 'raise Yo::ClientError' do
|
23
|
+
->{ subject.yo(username: ENV['YO_USER_NAME']) }.should raise_error(Yo::ClientError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when Yo API server is down' do
|
28
|
+
before { Yo::HTTP.any_instance.stub(:yo).and_raise(Yo::UnknownError) }
|
29
|
+
subject { Yo::Client.new(api_token: 'invalid_api_token') }
|
30
|
+
it 'raise Yo::UnknownError' do
|
31
|
+
->{ subject.yo(username: ENV['YO_USER_NAME']) }.should raise_error(Yo::UnknownError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#yoall' do
|
37
|
+
context 'with the valid api token' do
|
38
|
+
subject { Yo::Client.new(api_token: ENV['YO_API_TOKEN']) }
|
39
|
+
it "returns nil" do
|
40
|
+
subject.yoall.should eq(nil)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with an invalid api token' do
|
45
|
+
subject { Yo::Client.new(api_token: 'invalid_api_token') }
|
46
|
+
it "returns nil" do
|
47
|
+
subject.yoall.should eq(nil)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when Yo API server is down' do
|
52
|
+
before { Yo::HTTP.any_instance.stub(:yoall).and_raise(Yo::UnknownError) }
|
53
|
+
subject { Yo::Client.new(api_token: 'invalid_api_token') }
|
54
|
+
it 'raise Yo::UnknownError' do
|
55
|
+
->{ subject.yoall }.should raise_error(Yo::UnknownError)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#subscribers_count' do
|
61
|
+
context 'with the valid api token' do
|
62
|
+
subject { Yo::Client.new(api_token: ENV['YO_API_TOKEN']) }
|
63
|
+
it "returns Fixnum" do
|
64
|
+
subject.subscribers_count.kind_of?(Fixnum).should eq(true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'with an invalid api token' do
|
69
|
+
subject { Yo::Client.new(api_token: 'invalid_api_token') }
|
70
|
+
it 'raise Yo::ClientError' do
|
71
|
+
->{ subject.subscribers_count }.should raise_error(Yo::ClientError)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when Yo API server is down' do
|
76
|
+
before { Yo::HTTP.any_instance.stub(:subscribers_count).and_raise(Yo::UnknownError) }
|
77
|
+
subject { Yo::Client.new(api_token: ENV['YO_API_TOKEN']) }
|
78
|
+
it 'raise Yo::UnknownError' do
|
79
|
+
->{ subject.subscribers_count }.should raise_error(Yo::UnknownError)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/yo4r.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'yo4r/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "yo4r"
|
7
|
+
spec.version = Yo4r::VERSION
|
8
|
+
spec.authors = ["Tsukuru Tanimichi"]
|
9
|
+
spec.email = ["tanimichi@outlook.jp"]
|
10
|
+
spec.summary = 'A Ruby interface to the Yo API.'
|
11
|
+
spec.description = 'A Ruby interface to the Yo API.'
|
12
|
+
spec.homepage = "https://github.com/tanimichi/yo4r"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec", '~> 3.0.0'
|
23
|
+
spec.add_development_dependency "unindent"
|
24
|
+
spec.add_dependency 'faraday', '~> 0.9.0'
|
25
|
+
spec.required_ruby_version = '>= 2.1'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yo4r
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tsukuru Tanimichi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-03 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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: 3.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: unindent
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.0
|
83
|
+
description: A Ruby interface to the Yo API.
|
84
|
+
email:
|
85
|
+
- tanimichi@outlook.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/yo4r.rb
|
97
|
+
- lib/yo4r/client.rb
|
98
|
+
- lib/yo4r/errors.rb
|
99
|
+
- lib/yo4r/http.rb
|
100
|
+
- lib/yo4r/version.rb
|
101
|
+
- spec/client_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- yo4r.gemspec
|
104
|
+
homepage: https://github.com/tanimichi/yo4r
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '2.1'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.0
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: A Ruby interface to the Yo API.
|
128
|
+
test_files:
|
129
|
+
- spec/client_spec.rb
|
130
|
+
- spec/spec_helper.rb
|