twitch-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a2c0a000501b7f068e501cbd89d6768dd71d4953054f3e52f6b52e8a3ece44fe
4
+ data.tar.gz: 3f07b55c534c086fc20cec007b5b7b14c8aae6a70977ec488713a810462e4da5
5
+ SHA512:
6
+ metadata.gz: 2ea4e22e642a68541f5a5fb10f5e6ea19d52c1b55ce6a55e302235d35dda22dd5db119a4fa9f576a4708f22b21edeb41d295a656d3341d77065e062e9093c2ee
7
+ data.tar.gz: eb52773a0b6c62c3082c344f2016fff660e1c8a0ebde4c6dccee16b042c2c5e8c924f3f2d40379307d8214d358eb54063a6caadee52531e849cb386ff45b4c68
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # for a library or gem, you might want to ignore these files since the code is
14
+ # intended to run in multiple environments; otherwise, check them in:
15
+ Gemfile.lock
16
+ .ruby-version
17
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in twitch-api.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Maurice Wahba
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,43 @@
1
+ # Ruby Twitch API (work in progress)
2
+
3
+ This library is a Ruby implementation of the [Twitch Helix API](https://dev.twitch.tv/docs/api).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'twitch-api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install twitch-api
20
+
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.
23
+ ```
24
+ client = Twitch::Client.new client_id: "YOUR_CLIENT_ID"
25
+ # Get top live streams
26
+ client.get_streams
27
+ # Get a single user
28
+ client.get_users({login: "disguisedtoasths"}).first
29
+ ```
30
+
31
+ ## Development
32
+
33
+ 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
+
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).
36
+
37
+ ## Contributing
38
+
39
+ Upon reaching version 0.1.0, bug reports and pull requests will be welcome on GitHub at https://github.com/mauricew/ruby-twitch-api.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "twitch-api"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "twitch/version"
2
+ require "twitch/client"
3
+
4
+ module Twitch
5
+ end
@@ -0,0 +1,54 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ require "twitch/stream"
5
+ require "twitch/user"
6
+
7
+ module Twitch
8
+ class Client
9
+ API_ENDPOINT = "https://api.twitch.tv/helix".freeze
10
+
11
+ def initialize(client_id:, access_token: nil)
12
+ headers = {
13
+ "Client-ID": client_id,
14
+ "User-Agent": "twitch-api ruby client #{Twitch::VERSION}"
15
+ }
16
+ unless access_token.nil?
17
+ headers["Authorization"] = "Bearer #{access_token}"
18
+ end
19
+
20
+ @conn = Faraday.new(API_ENDPOINT, { headers: headers }) do |faraday|
21
+ faraday.response :json
22
+ faraday.adapter Faraday.default_adapter
23
+ end
24
+ end
25
+
26
+ def get_streams(options = {})
27
+ res = get('streams', options)
28
+
29
+ streams = res.body['data'].map { |s| Stream.new(s) }
30
+ end
31
+
32
+ def get_users(options = {})
33
+ res = get('users', options)
34
+
35
+ users = res.body['data'].map { |u| User.new(u) }
36
+ end
37
+
38
+ private
39
+
40
+ def get(resource, params)
41
+ res = @conn.get(resource, params)
42
+
43
+ unless res.status == 200
44
+ msg= %Q{The server returned an error.
45
+ #{res.body["error"]}: #{res.body["message"]}
46
+ Status: #{res.body["status"]}}
47
+
48
+ raise Exception.new(msg)
49
+ end
50
+
51
+ res
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ module Twitch
2
+ class Stream
3
+ attr_reader :id, :user_id, :game_id, :community_ids, :type, :title, :viewer_count, :started_at, :language, :thumbnail_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
@@ -0,0 +1,12 @@
1
+ module Twitch
2
+ class User
3
+ # All fields are read-only until update support is implemented
4
+ attr_reader :id, :login, :display_name, :type, :broadcaster_type, :description, :profile_image_url, :offline_image_url, :view_count
5
+
6
+ def initialize(attributes = {})
7
+ attributes.each do |k, v|
8
+ instance_variable_set("@#{k}", v)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Twitch
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "twitch/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "twitch-api"
8
+ spec.version = Twitch::VERSION
9
+ spec.authors = ["Maurice Wahba"]
10
+ spec.email = ["maurice.wahba@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby client for the Twitch Helix API.}
13
+ spec.homepage = "https://github.com/mauricew/ruby-twitch-api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "faraday", "~> 0.13"
24
+ spec.add_dependency "faraday_middleware", "~> 0.12"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twitch-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maurice Wahba
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-06 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.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
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.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
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.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
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:
84
+ email:
85
+ - maurice.wahba@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/twitch-api.rb
100
+ - lib/twitch/client.rb
101
+ - lib/twitch/stream.rb
102
+ - lib/twitch/user.rb
103
+ - lib/twitch/version.rb
104
+ - twitch-api.gemspec
105
+ homepage: https://github.com/mauricew/ruby-twitch-api
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Ruby client for the Twitch Helix API.
129
+ test_files: []