yo_client 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78689d15bfac530539523a79d1ff1b65b7ec300e
4
- data.tar.gz: 84bda1bec35c29c08d698a14671832175f7d8eab
3
+ metadata.gz: 8e3216adee4b8bf0b39ee3d5fb1f502e3f245903
4
+ data.tar.gz: b8a67600c9402e8869a0710c2f47cca422e8c09a
5
5
  SHA512:
6
- metadata.gz: c27e20590014c4e3291bf170ab86b7aca3a5b207baa1171ee3724b03590c223c0abb017d1987572cecd95aca36d8683f2b486b85120d5526c9facf54ff05fa0f
7
- data.tar.gz: 55f94566690d09a603149ba315697b17f87cbcf333fc326c676a4906c0fc2d613ccf2f692ee371d4e17afb2354ef59282a97f3179eb185faa229a549d06bfbae
6
+ metadata.gz: f2cb40dcf33f4ea81b7ac923cc12d1e7f7a836f9a37a70f1c6f2da4a78334e715b6617bf63bb028c3e55e6102160928e6f4263e3830caca79099fae1c2656272
7
+ data.tar.gz: 308199571d0deadf965f77a205acd041f701b8600190fd97c2c93158c7ff990a90455f84f2a126245c5d339143f55dd00bf0f742f17d8bb865ece9aa33d3d669
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.9.3
4
+ - 2.0.0
3
5
  - 2.1.2
data/README.md CHANGED
@@ -1,19 +1,26 @@
1
- # YoClient [![Build Status](https://travis-ci.org/youcune/yo_client.svg?branch=master)](https://travis-ci.org/youcune/yo_client)
1
+ # YoClient
2
2
 
3
3
  is a Ruby client of [Yo](http://www.justyo.co/).
4
+ [![Build Status](https://travis-ci.org/youcune/yo_client.svg?branch=master)](https://travis-ci.org/youcune/yo_client)
5
+ [![Coverage Status](https://coveralls.io/repos/youcune/yo_client/badge.png)](https://coveralls.io/r/youcune/yo_client)
6
+
7
+ ## Requirements
8
+
9
+ * Ruby 1.9+ (Tested on Ruby 1.9.3, 2.0.0, 2.1.2)
10
+ * [Yo API Account](http://dev.justyo.co/)
4
11
 
5
12
  ## Installation
6
13
 
7
14
  Add this line to your application's Gemfile:
8
15
 
9
16
  ```
10
- gem 'yo_client', github: 'youcune/yo_client'
17
+ gem 'yo_client'
11
18
  ```
12
19
 
13
20
  And then execute:
14
21
 
15
22
  ```
16
- $ bundle
23
+ $ bundle install
17
24
  ```
18
25
 
19
26
  ## Usage
@@ -21,17 +28,24 @@ $ bundle
21
28
  ```
22
29
  client = YoClient::Client.new(API_TOKEN)
23
30
 
24
- # Send A Yo To All Subscribers
31
+ # Yo all subscribers
25
32
  client.yoall
26
33
 
27
- # Yo Individual Usernames
28
- # Note that USERNAME will be upcased and sent to API
34
+ # Yo specific user
35
+ # Note that USERNAME will be upcased before sending to API
29
36
  client.yo(USERNAME)
30
37
 
31
38
  # Count Total Subscribers
32
39
  client.subscribers_count # -> 5
33
40
  ```
34
41
 
42
+ ### Error Handling
43
+
44
+ * `YoClient::ConnectionError` is risen if the connection has failed.
45
+ * `YoClient::ClientError` is risen if the connection has succeeded but API returned error.
46
+
47
+ At the date of 13th July, even if API results in failure, it sometimes behaves as if it succeed. In this case, YoClient cannot tell succeeded or not.
48
+
35
49
  ## Contributing
36
50
 
37
51
  1. Fork it ( https://github.com/youcune/yo_client/fork )
@@ -40,3 +54,12 @@ client.subscribers_count # -> 5
40
54
  4. Push to the branch (`git push origin my-new-feature`)
41
55
  5. Create a new Pull Request
42
56
 
57
+ ## Yo the author
58
+
59
+ [Yo YOUCUNE](http://justyo.co/YOUCUNE), author of YoClient, if you ...
60
+
61
+ * like YoClient
62
+ * dislike YoClient
63
+ * have any ideas about YoClient
64
+
65
+ Thanks.
data/lib/yo_client.rb CHANGED
@@ -5,7 +5,7 @@ require 'faraday_middleware'
5
5
  module YoClient
6
6
  class Client
7
7
  # Constructor
8
- # @param [String] token Yo API Token
8
+ # @param [String] api_token Yo API Token
9
9
  def initialize(api_token)
10
10
  @api_token = api_token
11
11
  @faraday = Faraday.new(url: 'http://api.justyo.co') do |faraday|
@@ -16,26 +16,58 @@ module YoClient
16
16
  end
17
17
 
18
18
  # Yo to all subscribers
19
+ # @return [Boolean] if request has succeed
19
20
  def yoall
20
- @faraday.post '/yoall/', token_hash
21
+ response = connection_wrapper {
22
+ @faraday.post '/yoall/', token_hash
23
+ }
24
+ response.success?
21
25
  end
22
26
 
23
27
  # Yo to specific user
24
- # @param [String] username
28
+ # @param [String] username usename to send yo
29
+ # @return [Boolean] if request has succeed
25
30
  def yo(username)
26
- @faraday.post '/yo/', token_hash.merge(username: username.upcase)
31
+ response = connection_wrapper {
32
+ @faraday.post '/yo/', token_hash.merge(username: username.upcase)
33
+ }
34
+ response.success?
27
35
  end
28
36
 
29
37
  # Get a number of subscribers
30
38
  # @return [Integer] number of subscribers
31
39
  def subscribers_count
32
- response = @faraday.get '/subscribers_count/', token_hash
40
+ response = connection_wrapper {
41
+ @faraday.get '/subscribers_count/', token_hash
42
+ }
33
43
  response.body['result']
34
44
  end
35
45
 
36
46
  private
47
+ # Connect with error handling
48
+ # @param [Proc] block
49
+ def connection_wrapper(&block)
50
+ begin
51
+ response = block.call
52
+ raise ClientError.new(response.body['error']) if response.body.has_key?('error')
53
+ rescue Faraday::ParsingError => e
54
+ # Has gotten a response, but it is not formatted with JSON
55
+ raise ClientError.new(e.message)
56
+ rescue Faraday::ClientError => e
57
+ # Failed to build a connection
58
+ raise ConnectionError.new(e.message)
59
+ end
60
+
61
+ response
62
+ end
63
+
64
+ # Returns hash for every request
65
+ # @return [Hash] hash for every request
37
66
  def token_hash
38
67
  { api_token: @api_token }
39
68
  end
40
69
  end
70
+
71
+ class ConnectionError < StandardError; end
72
+ class ClientError < StandardError; end
41
73
  end
@@ -1,3 +1,3 @@
1
1
  module YoClient
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,7 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'yo_client'
3
- require 'pry'
3
+
4
+ if ENV['TRAVIS']
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+ end
@@ -18,8 +18,8 @@ describe YoClient do
18
18
  it 'hooks POST /yoall/' do
19
19
  expect_any_instance_of(Faraday::Connection).to(
20
20
  receive(:post)
21
- .with('/yoall/', { api_token: 'test' })
22
- .and_return(double('yo', body: {}))
21
+ .with('/yoall/', { api_token: 'test' })
22
+ .and_return(double('yo', body: {}, success?: true))
23
23
  )
24
24
  @client.yoall
25
25
  end
@@ -29,8 +29,8 @@ describe YoClient do
29
29
  it 'hooks POST /yo/' do
30
30
  expect_any_instance_of(Faraday::Connection).to(
31
31
  receive(:post)
32
- .with('/yo/', { api_token: 'test', username: 'YOUCUNE' })
33
- .and_return(double('yo', body: {}))
32
+ .with('/yo/', { api_token: 'test', username: 'YOUCUNE' })
33
+ .and_return(double('yo', body: {}, success?: true))
34
34
  )
35
35
  @client.yo('youcune')
36
36
  end
@@ -40,7 +40,6 @@ describe YoClient do
40
40
  it 'hooks GET /subscribers_count/' do
41
41
  expect_any_instance_of(Faraday::Connection).to(
42
42
  receive(:get)
43
- .with('/subscribers_count/', { api_token: 'test' })
44
43
  .and_return(double('subscribers_count', body: { 'result' => 5 }))
45
44
  )
46
45
  expect(@client.subscribers_count).to eq 5
data/yo_client.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = YoClient::VERSION
9
9
  spec.authors = ['Yu Nakanishi']
10
10
  spec.email = ['you@nakanishi.email']
11
- spec.summary = 'Yo Client Library'
12
- spec.description = 'Yo Client Library'
11
+ spec.summary = 'Yo (http://www.justyo.co/) Ruby Client'
12
+ spec.description = 'Yo (http://www.justyo.co/) Ruby Client'
13
13
  spec.homepage = 'https://github.com/youcune/yo_client'
14
14
  spec.license = 'MIT'
15
15
 
@@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.6'
22
22
  spec.add_development_dependency 'rake'
23
- spec.add_development_dependency 'rspec'
24
- spec.add_development_dependency 'pry-byebug'
25
- spec.add_dependency 'faraday'
26
- spec.add_dependency 'faraday_middleware'
23
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
24
+ spec.add_development_dependency 'coveralls'
25
+ spec.add_dependency 'faraday', '~> 0.9.0'
26
+ spec.add_dependency 'faraday_middleware', '~> 0.9.0'
27
+ spec.required_ruby_version = '>= 1.9'
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yo_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yu Nakanishi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-12 00:00:00.000000000 Z
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,18 +42,18 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 3.0.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 3.0.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry-byebug
56
+ name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -70,37 +70,38 @@ dependencies:
70
70
  name: faraday
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.9.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.9.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: faraday_middleware
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.9.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
97
- description: Yo Client Library
96
+ version: 0.9.0
97
+ description: Yo (http://www.justyo.co/) Ruby Client
98
98
  email:
99
99
  - you@nakanishi.email
100
100
  executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".coveralls.yml"
104
105
  - ".gitignore"
105
106
  - ".rspec"
106
107
  - ".travis.yml"
@@ -125,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
126
  requirements:
126
127
  - - ">="
127
128
  - !ruby/object:Gem::Version
128
- version: '0'
129
+ version: '1.9'
129
130
  required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  requirements:
131
132
  - - ">="
@@ -136,7 +137,7 @@ rubyforge_project:
136
137
  rubygems_version: 2.2.2
137
138
  signing_key:
138
139
  specification_version: 4
139
- summary: Yo Client Library
140
+ summary: Yo (http://www.justyo.co/) Ruby Client
140
141
  test_files:
141
142
  - spec/spec_helper.rb
142
143
  - spec/yo_client_spec.rb