hots_api 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: 85fa5449294a897c754bd86e1b20a40fa582be9b
4
- data.tar.gz: 4a9d18c63be08574f5e655df491aab57faf55186
3
+ metadata.gz: 3089660b5c9e3dacd7f95292a7f1523e5749be9e
4
+ data.tar.gz: '0874565a44bd71426c2d8a103e6da9527c9768a5'
5
5
  SHA512:
6
- metadata.gz: ec51284bc413a0d7e21be5869e09ae8af8e4f475cc14ec0a0f61cc0dded102975996f1c230f8398c6a08a2e3b831c4398a13af4f2d3f21d0a81dbb22f54911e9
7
- data.tar.gz: 6630b7edadd30698a5e9d6026e46e6efff162a410619a42496d527a68fc8ff95ade71f688995b1896b7eb75dc60ec7145314ae966138aae19a1e9172965b0adf
6
+ metadata.gz: a9e2c44230b039fdf25f8b908bc55f06f80cf507f80a1d8c8e367198bd125034f4483a977b0293b70f5492180ef9a57089e1241e99d230cd7d05517aada0a278
7
+ data.tar.gz: 65f039f8da1c58da15fdd660406f53b958b25e9e4d1c1d5562d98c248d495379324dfd2898a7fb1c15da728a4a5a6bab33e470dfbff163fdaf832e41d589ce05
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/tbuehlmann/hots_api.svg?branch=master)](https://travis-ci.org/tbuehlmann/hots_api)
4
4
 
5
- HotsApi is an API client for the Heroes of the Storm replay metadata API [hotsapi.net](http://hotsapi.net/). It consumes the API and lets you retrieve information about uploaded replays.
5
+ HotsApi is an API client for the Heroes of the Storm replay metadata API [hotsapi.net](https://hotsapi.net/). It consumes the API and lets you retrieve information about uploaded replays.
6
6
 
7
7
  ## Installation
8
8
 
@@ -85,7 +85,16 @@ replays = HotsApi.replays.where(start_date: '2017-09-01 00:00').with_players.to_
85
85
 
86
86
  #### Pagination
87
87
 
88
- The API returns a maximum of 100 replays per request. If you want to retrieve all replays for a given query, use `find_each`:
88
+ The API returns a maximum of 100 replays per request. If you want to retrieve the second page (or the next 100 replays) for a given query:
89
+
90
+ ```ruby
91
+ first_page = HotsApi.replays
92
+ second_page = first_page.next_page
93
+ ```
94
+
95
+ Internally, this will set the appropriate `min_id` to the query. If there's no next page, calling `next_page` will return `nil`.
96
+
97
+ If you want to retrieve all replays for a given query, use `find_each`:
89
98
 
90
99
  ```ruby
91
100
  HotsApi.replays.where(start_date: '2017-09-01 00:00', end_date: '2017-09-01 23:59').find_each do |replay|
@@ -10,13 +10,13 @@ module HotsApi
10
10
 
11
11
  def get(path, params: {})
12
12
  with_retrying do
13
- HTTP.get("http://hotsapi.net/api/v1/#{path}", params: params)
13
+ HTTP.get("#{base_path}/#{path}", params: params)
14
14
  end
15
15
  end
16
16
 
17
17
  def post(path, body: nil, file: nil)
18
18
  with_retrying do
19
- HTTP.post("http://hotsapi.net/api/v1/#{path}", post_options_for(body: body, file: file))
19
+ HTTP.post("#{base_path}/#{path}", post_options_for(body: body, file: file))
20
20
  end
21
21
  end
22
22
 
@@ -29,6 +29,10 @@ module HotsApi
29
29
  end
30
30
  end
31
31
 
32
+ def base_path
33
+ 'https://hotsapi.net/api/v1'
34
+ end
35
+
32
36
  def with_retrying(tries: 10)
33
37
  tries.times do |try|
34
38
  response = yield
@@ -4,22 +4,22 @@ module HotsApi
4
4
  module Repositories
5
5
  class ReplayRepository < Repository
6
6
  def upload(file)
7
- response = HotsApi.post('replays', file: file)
7
+ response = HotsApi.post(path, file: file)
8
8
  Models::UploadedReplay.new(response.parse)
9
9
  end
10
10
 
11
11
  def trigger_hotslogs_upload(fingerprint)
12
- HotsApi.get("replays/fingerprints/v3/#{fingerprint}", params: {uploadToHotslogs: 1}).parse['exists']
12
+ HotsApi.get("#{path}/fingerprints/v3/#{fingerprint}", params: {uploadToHotslogs: 1}).parse['exists']
13
13
  end
14
14
 
15
15
  def fingerprint_uploaded?(fingerprint)
16
- HotsApi.get("replays/fingerprints/v3/#{fingerprint}").parse['exists']
16
+ HotsApi.get("#{path}/fingerprints/v3/#{fingerprint}").parse['exists']
17
17
  end
18
18
 
19
19
  def fingerprints_uploaded?(fingerprints)
20
20
  return {} if fingerprints.empty?
21
21
 
22
- upload_statuses = HotsApi.post('replays/fingerprints', body: fingerprints.join("\n")).parse
22
+ upload_statuses = HotsApi.post("#{path}/fingerprints", body: fingerprints.join("\n")).parse
23
23
 
24
24
  {}.tap do |fingerprint_statuses|
25
25
  upload_statuses['exists'].each do |fingerprint|
@@ -33,7 +33,7 @@ module HotsApi
33
33
  end
34
34
 
35
35
  def minimum_supported_build
36
- HotsApi.get('replays/min-build').to_s.to_i
36
+ HotsApi.get("#{path}/min-build").to_s.to_i
37
37
  end
38
38
 
39
39
  def with_players
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HotsApi
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hots_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Bühlmann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-18 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus