japic 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 +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +15 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/japic.gemspec +26 -0
- data/lib/japic.rb +9 -0
- data/lib/japic/client.rb +46 -0
- data/lib/japic/match.rb +26 -0
- data/lib/japic/rank.rb +27 -0
- data/lib/japic/response/base.rb +31 -0
- data/lib/japic/response/ranking.rb +15 -0
- data/lib/japic/response/schedule.rb +15 -0
- data/lib/japic/section.rb +12 -0
- data/lib/japic/url.rb +5 -0
- data/lib/japic/version.rb +3 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed2b713c009af2ead87fb46bedec855a5ab788e7
|
4
|
+
data.tar.gz: e1de5e9d022273a0376f5fa12a54dbee198d452c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59e736b8c65d2a62605f7e556db1d48fc44884e44bd86328ab55c84451a199a39c546e63630d3223194c211d8e296a3ea3f2b56ec7ddbd9fc6c12d37d08cc649
|
7
|
+
data.tar.gz: bb0e1bb56a6f8c5d3efd831cc11fa6d2471f98e5e1c34c0202a06800bd0676ef083f575cbf669c3a1dfce7679755eb9313237de26d468d6c43962d6a60222d46
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Japic
|
2
|
+
[Jleague API (unofficial)](http://labs.s-koichi.info/blog/archives/2014/02/08/1759-602.php) Client library implemented by ruby
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'japic'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install japic
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
client = Japic::Client.new
|
24
|
+
|
25
|
+
# if you want schedule( or result)
|
26
|
+
schedule = client.schedule(year: 2017, league: 'j1')
|
27
|
+
|
28
|
+
# or if you want ranking of n th section
|
29
|
+
ranking = client.ranking(year: 2017, league: 'j2', section: 1)
|
30
|
+
```
|
31
|
+
|
32
|
+
## TODO
|
33
|
+
|
34
|
+
- [ ] error handling
|
35
|
+
- [x] prepare an interface easy to use
|
36
|
+
- [ ] document of usage
|
37
|
+
- [ ] test
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/naoki-k/japic
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "japic"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/japic.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'japic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "japic"
|
8
|
+
spec.version = Japic::VERSION
|
9
|
+
spec.authors = ["Naoki Kanatani"]
|
10
|
+
spec.email = ["k12naoki@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{an API client liblary for Jleague API (unofficial)}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/naoki-k/japic"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday"
|
22
|
+
spec.add_dependency "faraday_middleware"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
data/lib/japic.rb
ADDED
data/lib/japic/client.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Japic
|
5
|
+
class Client
|
6
|
+
def connection
|
7
|
+
@connection ||=
|
8
|
+
::Faraday.new(url: URL::BASE) do |conn|
|
9
|
+
conn.response :json, content_type: /\bjson$/
|
10
|
+
conn.adapter Faraday.default_adapter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def schedule(year:, league:)
|
15
|
+
response(
|
16
|
+
'/api/jleague/V2/schedule',
|
17
|
+
Response::Schedule,
|
18
|
+
year,
|
19
|
+
league
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def ranking(year:, league:, section:)
|
24
|
+
response(
|
25
|
+
'/api/jleague/V2/standing',
|
26
|
+
Response::Ranking,
|
27
|
+
year,
|
28
|
+
league,
|
29
|
+
section
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def response(path, return_class, year, league, section = nil)
|
36
|
+
parameters = {
|
37
|
+
year: year,
|
38
|
+
league: league,
|
39
|
+
sec: section
|
40
|
+
}.delete_if { |_k, v| v.nil? }
|
41
|
+
|
42
|
+
response = connection.get(path, parameters)
|
43
|
+
return_class.new(response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/japic/match.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Japic
|
2
|
+
class Match
|
3
|
+
MATCH_DATA_TYPES = %w(
|
4
|
+
date
|
5
|
+
kickofftime
|
6
|
+
home
|
7
|
+
score
|
8
|
+
away
|
9
|
+
place
|
10
|
+
note
|
11
|
+
).map(&:freeze).freeze
|
12
|
+
|
13
|
+
attr_reader *MATCH_DATA_TYPES
|
14
|
+
|
15
|
+
def initialize(year, match_data)
|
16
|
+
@year = year
|
17
|
+
match_data.each do |k, v|
|
18
|
+
instance_variable_set(:"@#{k}", v) if MATCH_DATA_TYPES.include?(k)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def datetime
|
23
|
+
@datetime ||= DateTime.parse("#{@year}/#{@date} #{@kickofftime} JST")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/japic/rank.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Japic
|
2
|
+
class Rank
|
3
|
+
RANK_DATA_TYPES = %w(
|
4
|
+
order
|
5
|
+
team
|
6
|
+
points
|
7
|
+
gp
|
8
|
+
win
|
9
|
+
draw
|
10
|
+
lost
|
11
|
+
gf
|
12
|
+
ga
|
13
|
+
gd
|
14
|
+
).map(&:freeze).freeze
|
15
|
+
|
16
|
+
attr_reader *RANK_DATA_TYPES
|
17
|
+
|
18
|
+
def initialize(response_data)
|
19
|
+
# rename lank(rank's typo?) to order.
|
20
|
+
@order = response_data.delete('lank')
|
21
|
+
|
22
|
+
response_data.each do |k, v|
|
23
|
+
instance_variable_set(:"@#{k}", v) if RANK_DATA_TYPES.include?(k)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Japic
|
2
|
+
module Response
|
3
|
+
class Base
|
4
|
+
attr_reader :response
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
end
|
9
|
+
|
10
|
+
def body
|
11
|
+
response.body
|
12
|
+
end
|
13
|
+
|
14
|
+
def status
|
15
|
+
response.status
|
16
|
+
end
|
17
|
+
|
18
|
+
def year
|
19
|
+
body['year']
|
20
|
+
end
|
21
|
+
|
22
|
+
def league
|
23
|
+
body['league']
|
24
|
+
end
|
25
|
+
|
26
|
+
def count
|
27
|
+
body['count']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/japic/url.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: japic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naoki Kanatani
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: an API client liblary for Jleague API (unofficial)
|
84
|
+
email:
|
85
|
+
- k12naoki@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- japic.gemspec
|
100
|
+
- lib/japic.rb
|
101
|
+
- lib/japic/client.rb
|
102
|
+
- lib/japic/match.rb
|
103
|
+
- lib/japic/rank.rb
|
104
|
+
- lib/japic/response/base.rb
|
105
|
+
- lib/japic/response/ranking.rb
|
106
|
+
- lib/japic/response/schedule.rb
|
107
|
+
- lib/japic/section.rb
|
108
|
+
- lib/japic/url.rb
|
109
|
+
- lib/japic/version.rb
|
110
|
+
homepage: https://github.com/naoki-k/japic
|
111
|
+
licenses: []
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.6.10
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: an API client liblary for Jleague API (unofficial)
|
133
|
+
test_files: []
|