twitch-api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2c0a000501b7f068e501cbd89d6768dd71d4953054f3e52f6b52e8a3ece44fe
4
- data.tar.gz: 3f07b55c534c086fc20cec007b5b7b14c8aae6a70977ec488713a810462e4da5
3
+ metadata.gz: ac33cdb4eea079d0b42b33b7eabe032559a53a491e31ea89c0631820f1e0fcd4
4
+ data.tar.gz: e3dac26f11d2560eaed250cac580be1c4a9c260d2a2d2cd8fbd3db011eae1fba
5
5
  SHA512:
6
- metadata.gz: 2ea4e22e642a68541f5a5fb10f5e6ea19d52c1b55ce6a55e302235d35dda22dd5db119a4fa9f576a4708f22b21edeb41d295a656d3341d77065e062e9093c2ee
7
- data.tar.gz: eb52773a0b6c62c3082c344f2016fff660e1c8a0ebde4c6dccee16b042c2c5e8c924f3f2d40379307d8214d358eb54063a6caadee52531e849cb386ff45b4c68
6
+ metadata.gz: dbcfd386114ef19bd142faa9d768acff1dfe83adaa21fec029e7c3cc517ed664d7f24f7bcd112449ebf8eb9b2306f6727200a344064026ffabbda154ee848a6a
7
+ data.tar.gz: e40a2a3c7635ce58ab7b05a96b682b34e46549135e9874ec4ac7ad97088157acecfe18939b80c11ecaf9effe95179bef5b066e6154a7cfc8e42813c9bfcc28ba
data/README.md CHANGED
@@ -19,20 +19,28 @@ Or install it yourself as:
19
19
  $ gem install twitch-api
20
20
 
21
21
  ## Usage
22
- The initially available methods take in a hash equal to the GET parameters of the API endpoint, and return an typed array of the items requested.
22
+ NOTE: **These procedures are subject to change** while both the API and this library are in an early state.
23
+
24
+ A client must be initialized with your client ID, and optionally an OAuth access token.
23
25
  ```
24
26
  client = Twitch::Client.new client_id: "YOUR_CLIENT_ID"
27
+ ```
28
+ The retrieval methods take in a hash equal to the GET parameters of the API endpoint, and return an typed array of the items requested.
29
+ ```
25
30
  # Get top live streams
26
31
  client.get_streams
27
32
  # Get a single user
28
33
  client.get_users({login: "disguisedtoasths"}).first
34
+ # Find some games
35
+ # (use an array for up to 100 of most queryable resources)
36
+ client.get_games({name: ["Heroes of the Storm", "Super Mario Odyssey"]})
29
37
  ```
30
38
 
31
39
  ## Development
32
40
 
33
41
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
42
 
35
- 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).
43
+ To install this gem onto your local machine, run `bundle exec rake install`.
36
44
 
37
45
  ## Contributing
38
46
 
@@ -3,6 +3,8 @@ require "faraday_middleware"
3
3
 
4
4
  require "twitch/stream"
5
5
  require "twitch/user"
6
+ require "twitch/game"
7
+ require "twitch/video"
6
8
 
7
9
  module Twitch
8
10
  class Client
@@ -35,6 +37,18 @@ module Twitch
35
37
  users = res.body['data'].map { |u| User.new(u) }
36
38
  end
37
39
 
40
+ def get_games(options = {})
41
+ res = get('games', options)
42
+
43
+ games = res.body['data'].map { |g| Game.new(g) }
44
+ end
45
+
46
+ def get_videos(options = {})
47
+ res = get('videos', options)
48
+
49
+ videos = res.body['data'].map { |v| Video.new(v) }
50
+ end
51
+
38
52
  private
39
53
 
40
54
  def get(resource, params)
@@ -0,0 +1,11 @@
1
+ module Twitch
2
+ class Game
3
+ attr_reader :id, :name, :box_art_url
4
+
5
+ def initialize(attributes = {})
6
+ attributes.each do |k, v|
7
+ instance_variable_set("@#{k}", v)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,10 +1,17 @@
1
+ require "time"
2
+
1
3
  module Twitch
2
4
  class Stream
3
5
  attr_reader :id, :user_id, :game_id, :community_ids, :type, :title, :viewer_count, :started_at, :language, :thumbnail_url
4
-
6
+ DATE_ATTRIBUTES = [:started_at]
7
+
5
8
  def initialize(attributes = {})
6
9
  attributes.each do |k, v|
7
- instance_variable_set("@#{k}", v)
10
+ if DATE_ATTRIBUTES.include?(k.to_sym)
11
+ instance_variable_set("@#{k}", Time.parse(v))
12
+ else
13
+ instance_variable_set("@#{k}", v)
14
+ end
8
15
  end
9
16
  end
10
17
  end
@@ -1,3 +1,3 @@
1
1
  module Twitch
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require "time"
2
+
3
+ module Twitch
4
+ class Video
5
+ DATE_ATTRIBUTES = [:created_at, :published_at]
6
+
7
+ attr_reader :id, :title, :description, :language, :view_count, :created_at, :published_at, :thumbnail_url
8
+
9
+ def initialize(attributes = {})
10
+ attributes.each do |k, v|
11
+ if DATE_ATTRIBUTES.include?(k.to_sym)
12
+ instance_variable_set("@#{k}", Time.parse(v))
13
+ else
14
+ instance_variable_set("@#{k}", v)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{Ruby client for the Twitch Helix API.}
13
13
  spec.homepage = "https://github.com/mauricew/ruby-twitch-api"
14
14
  spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.0"
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
18
  f.match(%r{^(test|spec|features)/})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitch-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maurice Wahba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -98,9 +98,11 @@ files:
98
98
  - bin/setup
99
99
  - lib/twitch-api.rb
100
100
  - lib/twitch/client.rb
101
+ - lib/twitch/game.rb
101
102
  - lib/twitch/stream.rb
102
103
  - lib/twitch/user.rb
103
104
  - lib/twitch/version.rb
105
+ - lib/twitch/video.rb
104
106
  - twitch-api.gemspec
105
107
  homepage: https://github.com/mauricew/ruby-twitch-api
106
108
  licenses:
@@ -114,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
116
  requirements:
115
117
  - - ">="
116
118
  - !ruby/object:Gem::Version
117
- version: '0'
119
+ version: '2.0'
118
120
  required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  requirements:
120
122
  - - ">="