strife 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ .env
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in strife.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Anthony White
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,34 @@
1
+ # Strife
2
+
3
+ Strife is a ruby wrapper for the Riot Games League of Legends APIs.
4
+
5
+ I will be attempting to maintain compatibility with ONLY the latest
6
+ version of each API that Riot releases. According to Riot's
7
+ documentation, they will only support previous versions of an API
8
+ for up to 60 days, allowing clients time to upgrade existing calls.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'strife'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install strife
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ module Strife
2
+ class Client
3
+ module Champion
4
+ VERSION = 'v1.1'
5
+
6
+ def champion(options = {})
7
+ options.reverse_merge!(freeToPlay: false)
8
+
9
+ get "v1.1/champion", options
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Strife
2
+ class Client
3
+ module Game
4
+ def recent_games_by_summoner(options = {})
5
+ get "v1.2/game/by-summoner/#{options.delete(:summoner_id)}/recent", options
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Strife
2
+ class Client
3
+ module League
4
+ def league_by_summoner(options = {})
5
+ get "v2.2/league/by-summoner/#{options.delete(:summoner_id)}", options
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Strife
2
+ class Client
3
+ module Stats
4
+ def ranked_stats_by_summoner(options = {})
5
+ get "v1.2/stats/by-summoner/#{summoner_id}/ranked", options
6
+ end
7
+
8
+ def summary_stats_by_summoner(options = {})
9
+ get "v1.2/stats/by-summoner/#{summoner_id}/summary", options
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ module Strife
2
+ class Client
3
+ module Summoner
4
+ VERSION = "v1.2"
5
+
6
+ def summoner_masteries(options = {})
7
+ get "v1.2/summoner/#{options.delete(:summoner_id)}/masteries", options
8
+ end
9
+
10
+ def summoner_runes(options = {})
11
+ get "v1.2/summoner/#{options.delete(:summoner_id)}/runes", options
12
+ end
13
+
14
+ def summoner_by_name(options = {})
15
+ get "v1.2/summoner/by-name/#{options.delete(:name)}", options
16
+ end
17
+
18
+ def summoner_by_id(options = {})
19
+ get "v1.2/summoner/#{options.delete(:summoner_id)}", options
20
+ end
21
+
22
+ def summoner_names(options = {})
23
+ summoner_ids = options.delete(:summoner_ids).join(',')
24
+
25
+ raise ArgumentError.new("You can not query more than 40 summoner names at one time") if summoner_ids.length > 40
26
+
27
+ get "v1.2/summoner/#{summoner_ids}/name", options
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ module Strife
2
+ class Client
3
+ module Team
4
+ def team_by_summoner_id(options = {})
5
+ summoner_id = options.delete(:summoner_id)
6
+
7
+ get "v2.2/team/by-summoner/#{summoner_id}", options
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,76 @@
1
+ require 'sawyer'
2
+ require 'strife/configurable'
3
+ require 'strife/client/champion'
4
+ require 'strife/client/game'
5
+ require 'strife/client/league'
6
+ require 'strife/client/stats'
7
+ require 'strife/client/summoner'
8
+ require 'strife/client/team'
9
+
10
+ module Strife
11
+ class Client
12
+ include Strife::Configurable
13
+ include Strife::Client::Champion
14
+ include Strife::Client::Game
15
+ include Strife::Client::League
16
+ include Strife::Client::Stats
17
+ include Strife::Client::Summoner
18
+ include Strife::Client::Team
19
+
20
+ def initialize(options = {})
21
+ Strife::Configurable.keys.each do |key|
22
+ instance_variable_set(:"@#{key}", options[key] || Strife.instance_variable_get(:"@#{key}"))
23
+ end
24
+ end
25
+
26
+ def same_options?(opts)
27
+ opts.hash == options.hash
28
+ end
29
+
30
+ # Scrub out our api key from #inspect
31
+ def inspect
32
+ inspected = super
33
+
34
+ inspected = inspected.gsub! @api_key, '*' * @api_key.length
35
+
36
+ inspected
37
+ end
38
+
39
+ def get(url, options = {})
40
+ request :get, url, options
41
+ end
42
+
43
+ def last_response
44
+ @last_response
45
+ end
46
+
47
+ def agent
48
+ @agent ||= Sawyer::Agent.new("#{@api_endpoint}#{@region}/", sawyer_options) do |http|
49
+ http.headers[:accept] = @default_media_type
50
+ http.headers[:user_agent] = @user_agent
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def sawyer_options
57
+ opts = {
58
+ links_parser: Sawyer::LinkParsers::Simple.new
59
+ }
60
+
61
+ conn_opts = @connection_options
62
+ conn_opts[:builder] = @middleware if @middleware
63
+ opts[:faraday] = Faraday.new(conn_opts)
64
+
65
+ opts
66
+ end
67
+
68
+ def request(method, path, options)
69
+ options[:query] ||= {}
70
+ options[:query].merge!(api_key: @api_key)
71
+
72
+ @last_response = response = agent.call(method, URI.encode(path.to_s), options)
73
+ response.data
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,39 @@
1
+ module Strife
2
+ module Configurable
3
+ attr_accessor :api_key, :region
4
+ attr_writer :api_endpoint
5
+
6
+ class << self
7
+ def keys
8
+ @keys ||= [
9
+ :api_key,
10
+ :api_endpoint,
11
+ :user_agent,
12
+ :default_media_type,
13
+ :connection_options,
14
+ :middleware,
15
+ :region
16
+ ]
17
+ end
18
+ end
19
+
20
+ def configure
21
+ yield self
22
+ end
23
+
24
+ def reset!
25
+ Strife::Configurable.keys.each do |key|
26
+ instance_variable_set(:"@#{key}", Strife::Default.options[key])
27
+ end
28
+
29
+ self
30
+ end
31
+ alias setup reset!
32
+
33
+ private
34
+
35
+ def options
36
+ Hash[Strife::Configurable.keys.map {|key| [key, instance_variable_get(:"@#{key}")]}]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def reverse_merge(other)
3
+ other.merge(self)
4
+ end
5
+
6
+ def reverse_merge!(other)
7
+ merge!(other) { |key, left, right| left }
8
+ end
9
+ end
@@ -0,0 +1,61 @@
1
+ require 'strife/response/raise_error'
2
+ require 'faraday-http-cache'
3
+ require 'strife/version'
4
+
5
+ module Strife
6
+ module Default
7
+ API_ENDPOINT = 'http://prod.api.pvp.net/api/lol/'.freeze
8
+
9
+ USER_AGENT = "Strife Riot API GEM v#{Strife::VERSION}".freeze
10
+
11
+ MEDIA_TYPE = 'application/json'.freeze
12
+
13
+ REGION = 'na'.freeze
14
+
15
+ MIDDLEWARE = Faraday::Builder.new do |builder|
16
+ builder.use Strife::Response::RaiseError
17
+ builder.use :http_cache, store: :memory_store
18
+ builder.adapter Faraday.default_adapter
19
+ end
20
+
21
+ # Default options
22
+ class << self
23
+ def options
24
+ Hash[Strife::Configurable.keys.map {|key| [key, send(key)]}]
25
+ end
26
+
27
+ def api_key
28
+ ENV['STRIFE_API_KEY']
29
+ end
30
+
31
+ def api_endpoint
32
+ ENV['STRIFE_API_ENDPOINT'] || API_ENDPOINT
33
+ end
34
+
35
+ def user_agent
36
+ ENV['STRIFE_USER_AGENT'] || USER_AGENT
37
+ end
38
+
39
+ def default_media_type
40
+ ENV['STRIFE_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE
41
+ end
42
+
43
+ def middleware
44
+ MIDDLEWARE
45
+ end
46
+
47
+ def connection_options
48
+ {
49
+ headers: {
50
+ accept: default_media_type,
51
+ user_agent: user_agent
52
+ }
53
+ }
54
+ end
55
+
56
+ def region
57
+ ENV['STRIFE_REGION'] || REGION
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ module Strife
2
+ class Error < StandardError
3
+ def self.from_response(response)
4
+ status = response[:status].to_i
5
+
6
+ if klass = case status
7
+ when 400 then BadRequest
8
+ when 401 then NotAuthorizedError
9
+ when 500 then InternalServerError
10
+ end
11
+ klass.new(response)
12
+ end
13
+ end
14
+
15
+ class ClientError < Error; end
16
+ class NotAuthorizedError < ClientError; end
17
+ class BadRequest < ClientError; end
18
+
19
+ class ServerError < Error; end
20
+ class InternalServerError < ServerError; end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ require 'faraday'
2
+ require 'strife/error'
3
+
4
+ module Strife
5
+ module Response
6
+ class RaiseError < Faraday::Response::Middleware
7
+ private
8
+ def on_complete(response)
9
+ if error = Strife::Error.from_response(response)
10
+ raise error
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Strife
2
+ VERSION = "0.0.1"
3
+ end
data/lib/strife.rb ADDED
@@ -0,0 +1,38 @@
1
+ require "strife/version"
2
+ require 'strife/core_ext/hash'
3
+ require "strife/client"
4
+ require "strife/default"
5
+
6
+ module Strife
7
+
8
+ class << self
9
+ include Strife::Configurable
10
+
11
+ def client
12
+ @client ||= Strife::Client.new(options) unless defined?(@client) && @client.same_options?(options)
13
+ @client
14
+ end
15
+
16
+ # @private
17
+ def respond_to_missing?(method_name, include_private = false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
18
+ # @private
19
+ def respond_to?(method_name, include_private = false); client.respond_to?(method_name, include_private); end if RUBY_VERSION < "1.9"
20
+
21
+ private
22
+
23
+ def method_missing(method_name, *args, &block)
24
+ return super unless client.respond_to?(method_name)
25
+
26
+ client.send(method_name, *args, &block)
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ begin
33
+ require 'dotenv'
34
+ Dotenv.load
35
+ rescue LoadError => e
36
+ end
37
+
38
+ Strife.setup
data/strife.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'strife/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "strife"
8
+ spec.version = Strife::VERSION
9
+ spec.authors = ["Anthony White"]
10
+ spec.email = ["anthony.white.j@gmail.com"]
11
+ spec.description = %q{Strife is a ruby wrapper for the Riot API. This product is not endorsed, certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.}
12
+ spec.summary = %q{Strife is a ruby wrapper for the Riot API This product is not endorsed, certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "pry-doc"
26
+ spec.add_development_dependency "dotenv"
27
+
28
+ spec.add_runtime_dependency "sawyer"
29
+ spec.add_runtime_dependency "faraday-http-cache"
30
+ end
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strife
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anthony White
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry-doc
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: dotenv
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: sawyer
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: faraday-http-cache
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Strife is a ruby wrapper for the Riot API. This product is not endorsed,
143
+ certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.
144
+ email:
145
+ - anthony.white.j@gmail.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - lib/strife.rb
156
+ - lib/strife/client.rb
157
+ - lib/strife/client/champion.rb
158
+ - lib/strife/client/game.rb
159
+ - lib/strife/client/league.rb
160
+ - lib/strife/client/stats.rb
161
+ - lib/strife/client/summoner.rb
162
+ - lib/strife/client/team.rb
163
+ - lib/strife/configurable.rb
164
+ - lib/strife/core_ext/hash.rb
165
+ - lib/strife/default.rb
166
+ - lib/strife/error.rb
167
+ - lib/strife/response/raise_error.rb
168
+ - lib/strife/version.rb
169
+ - strife.gemspec
170
+ homepage: ''
171
+ licenses:
172
+ - MIT
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 1.8.23
192
+ signing_key:
193
+ specification_version: 3
194
+ summary: Strife is a ruby wrapper for the Riot API This product is not endorsed,
195
+ certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.
196
+ test_files: []
197
+ has_rdoc: