-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a new endpoint for `Projections` * Add a new endpoint for `Leagues` * Responses now return an object with the data mapped * Add test coverage
- Loading branch information
Showing
31 changed files
with
878 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
release-please: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: GoogleCloudPlatform/release-please-action@v2 | ||
id: release | ||
with: | ||
release-type: ruby | ||
package-name: prizepicks | ||
bump-minor-pre-major: true | ||
version-file: "lib/prizepicks/version.rb" | ||
# Checkout code if release was created | ||
- uses: actions/checkout@v2 | ||
if: ${{ steps.release.outputs.release_created }} | ||
# Setup ruby if a release was created | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 3.0.0 | ||
if: ${{ steps.release.outputs.release_created }} | ||
# Bundle install | ||
- run: bundle install | ||
if: ${{ steps.release.outputs.release_created }} | ||
# Publish | ||
- name: publish gem | ||
run: | | ||
mkdir -p $HOME/.gem | ||
touch $HOME/.gem/credentials | ||
chmod 0600 $HOME/.gem/credentials | ||
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials | ||
gem build *.gemspec | ||
gem push *.gem | ||
env: | ||
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" | ||
if: ${{ steps.release.outputs.release_created }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'prizepicks/version' | ||
require 'prizepicks/config' | ||
|
||
require 'faraday' | ||
require 'faraday-cookie_jar' | ||
|
||
require 'prizepicks/version' | ||
# require 'prizepicks/config' | ||
require_relative 'prizepicks/faraday/connection' | ||
require_relative 'prizepicks/faraday/request' | ||
require_relative 'prizepicks/api/endpoints' | ||
require_relative 'prizepicks/client' | ||
# require_relative 'prizepicks/client' | ||
|
||
module PrizePicks | ||
autoload :Client, 'prizepicks/client' | ||
autoload :Collection, 'prizepicks/collection' | ||
autoload :Config, 'prizepicks/config' | ||
autoload :Error, 'prizepicks/error' | ||
|
||
# Responses | ||
autoload :Responses, 'prizepicks/api/responses' | ||
|
||
# module Prizepicks | ||
# class Error < StandardError; end | ||
# # Your code goes here... | ||
# end | ||
# Object | ||
autoload :Base, 'prizepicks/objects/base' | ||
autoload :Entry, 'prizepicks/objects/entry' | ||
autoload :League, 'prizepicks/objects/league' | ||
autoload :Projection, 'prizepicks/objects/projection' | ||
autoload :User, 'prizepicks/objects/user' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
module Api | ||
module Endpoints | ||
module Leagues | ||
ENDPOINT = '/v1/leagues' | ||
|
||
def leagues(options = {}) | ||
resp = request(:get, ENDPOINT, options) | ||
Collection.from_response(resp, type: League) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
module Api | ||
module Endpoints | ||
module Projections | ||
ENDPOINT = '/v1/projections' | ||
|
||
def projections(options = {}) | ||
resp = request(:get, ENDPOINT, options) | ||
Collection.from_response(resp, type: Projection) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
module Api | ||
module Responses | ||
class User < OpenStruct | ||
def initialize(attributes) | ||
super to_obstruct(attributes) | ||
end | ||
|
||
def to_obstruct(_attributes) | ||
case obj | ||
when Hash | ||
OpenStruct.new(obj.transform_values { |val| to_obstruct(val) }) | ||
when Array | ||
obj.map { |o| to_obstruct(o) } | ||
else | ||
obj | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
class Collection | ||
attr_reader :data, :total_pages, :current_page | ||
|
||
def self.from_response(response, type:) | ||
new( | ||
data: response['data'].map { |attrs| type.new(attrs) }, | ||
current_page: response.dig('meta', 'current_page'), | ||
total_pages: response.dig('meta', 'total_pages') | ||
) | ||
end | ||
|
||
def initialize(data:, current_page:, total_pages:) | ||
@data = data | ||
@current_page = current_page | ||
@total_pages = total_pages | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
class Error < StandardError; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
require 'ostruct' | ||
|
||
module PrizePicks | ||
class Base < OpenStruct | ||
def initialize(resp) | ||
@resp = resp | ||
super to_obstruct(resp.dig('data', 'attributes')) | ||
end | ||
|
||
def data | ||
@resp['data'] | ||
end | ||
|
||
def to_obstruct(obj) | ||
case obj | ||
when Hash | ||
OpenStruct.new(obj.transform_values { |val| to_obstruct(val) }) | ||
when Array | ||
obj.map { |o| to_obstruct(o) } | ||
else | ||
obj | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
class Entry < Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
class League < Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
class Projection < Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
module PrizePicks | ||
class User < Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Prizepicks | ||
module PrizePicks | ||
VERSION: String | ||
# See the writing guide of rbs: https://github.com/ruby/rbs#guides | ||
end |
Oops, something went wrong.