ow_api 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f3fc3e47de9f4e6a2eb3b2e917180bb85b6b312
4
+ data.tar.gz: e35762effc844522215b618f4727f42fd6207011
5
+ SHA512:
6
+ metadata.gz: 9988013fbbca113b3ae36b5e62079ea66e3a52dd089c4e55500389aeecc19d49062b851ce60aa335b923b0c83bf3927c37b2516751833de42c7a1a1fd55ca698
7
+ data.tar.gz: ae7e55f2d541ac6a09f464cb661b06a732e708b7ad1a4fb8764ff05d43b3e3af26823072aedb89f97d84bdad9d74008ff6e651c783fad13ee217ef326ce0f93a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 1.16.4
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 ow_api.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 James Gayfer
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.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # OwApi
2
+
3
+ Ruby wrapper for the [OW-API](https://ow-api.com/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ow_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ow_api
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ require 'ow_api`
25
+
26
+ client = OwApi.new
27
+ profile = client.profile(platform: 'pc', region: 'us', battletag: 'Asal-1502')
28
+ ```
29
+
30
+ For additional information on the expected arguments, see the [OW-API documenation](https://ow-api.com/docs/).
31
+
32
+ ## Development
33
+
34
+ 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.
35
+
36
+ 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).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[jgayfer]/ow_api.
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ow_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__)
data/bin/setup ADDED
@@ -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,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://ow-api.com/v1/stats/pc/us/Asal-1502/profile
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/1.14.1
23
+ Date:
24
+ - Mon, 07 Jan 2019 04:23:37 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Content-Length:
28
+ - '1085'
29
+ Connection:
30
+ - keep-alive
31
+ Vary:
32
+ - Origin
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"competitiveStats":{"awards":{"cards":9,"medals":70,"medalsBronze":23,"medalsSilver":23,"medalsGold":24},"games":{"played":28,"won":17}},"endorsement":2,"endorsementIcon":"https://d3hmvhl7ru3t12.cloudfront.net/svg/icons/endorsement-frames-aa182c1f63b51afa951daec63595791283ab97ea3a07f8d47abf9dc7aeda5cc67c786041042de0b8e427194ed084f7cee6b56fa984532199e7ea95bc12bbd995.svg#_2","gamesWon":869,"icon":"https://d15f34w2p8l1cc.cloudfront.net/overwatch/de972a209037f7cadafa6b46130de2e5a87636220a4dea317348d7b3c7ce12e3.png","level":45,"levelIcon":"https://d15f34w2p8l1cc.cloudfront.net/overwatch/888c84f2dfd211cde0c595036574040ca96b1698578daab90ce6822d89f7fe0e.png","name":"Asal#1502","prestige":3,"prestigeIcon":"https://d15f34w2p8l1cc.cloudfront.net/overwatch/888c84f2dfd211cde0c595036574040ca96b1698578daab90ce6822d89f7fe0e.png","private":false,"quickPlayStats":{"awards":{"cards":284,"medals":1676,"medalsBronze":482,"medalsSilver":549,"medalsGold":645},"games":{"played":0,"won":362}},"rating":2390,"ratingIcon":"https://d1u1mce87gyfbn.cloudfront.net/game/rank-icons/rank-GoldTier.png"}'
36
+ http_version:
37
+ recorded_at: Mon, 07 Jan 2019 04:23:37 GMT
38
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,12 @@
1
+ require 'ow_api/response/profile'
2
+
3
+ module OwApi
4
+ class Client
5
+ module Profile
6
+ def profile(platform:, region:, battletag:)
7
+ response = get("stats/#{platform}/#{region}/#{battletag}/profile")
8
+ handle_response(response, Response::Profile)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ require 'ow_api/client/profile'
5
+ require 'ow_api/interactors/hash_keys_to_snake_case'
6
+
7
+ module OwApi
8
+ class Client
9
+ include Profile
10
+
11
+ BASE_URL = 'https://ow-api.com'
12
+
13
+ private
14
+
15
+ def get(path)
16
+ URI.parse("#{BASE_URL}/v1/#{path}").read
17
+ end
18
+
19
+ def handle_response(response, klass)
20
+ json_response = JSON.parse(response)
21
+ snake_case_response = Interactors::HashKeysToSnakeCase.new.call(json_response)
22
+ klass.new(snake_case_response)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ module OwApi
2
+ module Interactors
3
+ class HashKeysToSnakeCase
4
+ def call(hash)
5
+ convert_hash_keys(hash)
6
+ end
7
+
8
+ private
9
+
10
+ def convert_hash_keys(value)
11
+ case value
12
+ when Array
13
+ value.map { |v| convert_hash_keys(v) }
14
+ when Hash
15
+ Hash[value.map { |k, v| [underscore_key(k), convert_hash_keys(v)] }]
16
+ else
17
+ value
18
+ end
19
+ end
20
+
21
+ def underscore_key(key)
22
+ key.
23
+ to_s.
24
+ gsub(/::/, '/').
25
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
26
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
27
+ tr("-", "_").
28
+ downcase
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ module OwApi
2
+ module Response
3
+ class Base
4
+ attr_reader :attrs
5
+ alias to_h attrs
6
+
7
+ class << self
8
+ def attr_reader(*attrs)
9
+ attrs.each do |attr|
10
+ define_method(attr) { @attrs && @attrs[attr.to_s] }
11
+ end
12
+ end
13
+ end
14
+
15
+ def initialize(attrs = {})
16
+ @attrs = attrs
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ require 'ow_api/response/base'
2
+
3
+ module OwApi
4
+ module Response
5
+ class Profile < Base
6
+ attr_reader :icon, :name, :level, :level_icon, :prestige, :prestige_icon,
7
+ :rating, :rating_icon, :games_won, :private, :endorsement_icon,
8
+ :endorsement
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module OwApi
2
+ VERSION = "0.1.1"
3
+ end
data/lib/ow_api.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'ow_api/version'
2
+ require 'ow_api/client'
3
+
4
+ module OwApi
5
+ class << self
6
+ def new
7
+ Client.new
8
+ end
9
+ end
10
+ end
data/ow_api.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ow_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ow_api"
8
+ spec.version = OwApi::VERSION
9
+ spec.authors = ["James Gayfer"]
10
+ spec.email = ["gayfer.james@gmail.com"]
11
+
12
+ spec.summary = "A Ruby client to consume the OW-API (https://ow-api.com/)"
13
+ spec.homepage = "https://github.com/jgayfer/overwatch-api"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 2"
26
+ spec.add_development_dependency "rake", "~> 12.3"
27
+ spec.add_development_dependency "rspec", "~> 3.8"
28
+ spec.add_development_dependency "vcr", "~> 4.0"
29
+ spec.add_development_dependency "webmock", "~> 3.5"
30
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ow_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - James Gayfer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ description:
84
+ email:
85
+ - gayfer.james@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
+ - fixtures/vcr_cassettes/profile.yml
100
+ - lib/ow_api.rb
101
+ - lib/ow_api/client.rb
102
+ - lib/ow_api/client/profile.rb
103
+ - lib/ow_api/interactors/hash_keys_to_snake_case.rb
104
+ - lib/ow_api/response/base.rb
105
+ - lib/ow_api/response/profile.rb
106
+ - lib/ow_api/version.rb
107
+ - ow_api.gemspec
108
+ homepage: https://github.com/jgayfer/overwatch-api
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.5.2.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A Ruby client to consume the OW-API (https://ow-api.com/)
132
+ test_files: []