prizepicks 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
  SHA256:
3
- metadata.gz: 5d51524708c35ebc1f268da73f0e1e775ad73fe1cf934298b213d00780caa955
4
- data.tar.gz: 60d1d5ea95ba5b19c852d0d072a8c72a52206c3298a914c611ffe255a3db19be
3
+ metadata.gz: 41d5091bcbfd11b34a1832b303f7682adf0a588fb780b036b6e826be05cea48d
4
+ data.tar.gz: f0f2f27500ed1cc7386be53cbdbec0fd80e494f4c7dad86bdad97a83d34c7030
5
5
  SHA512:
6
- metadata.gz: e56a6da76f6becb43d8bbee75775b1bc7c1f7386976af7eb084630f745167a6d6a10ea9fbdc7975606d2c713339a185acc31f3fc6483c751f7bf16c53fdb5c9e
7
- data.tar.gz: 230cb86cef2c1b04e83c02dcd64b5fe36202d3d3da0290b99bd39e19042618c997038d62ec3c13e290aa597314fa654324c5b45bd1d76445d06174cdedc73536
6
+ metadata.gz: ec535de7d275485a9330aa3c470dd80305f39b2303a84e286dc0b67e2e32c3ee5ae154a3b4b9bc42b8ffd1c93a05856d610b718724a30a4dd56bd0ade3d159bf
7
+ data.tar.gz: c312dc4c6e07ea7a17e110397328b0aea226c850e584dedefcc141a0c4d53c2b6fdc089b4b00ef28eec151dcdf9bc4be933afae2d52aa6694cd44572709ce0b2
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [0.2.0](https://www.github.com/troyizzle/prizepicks/compare/v0.1.0...v0.2.0) (2023-02-20)
4
+
5
+
6
+ ### Features
7
+
8
+ * add more endpoints ([75cff34](https://www.github.com/troyizzle/prizepicks/commit/75cff345d2be7d76535db484a3ea0c6bffb436ff))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prizepicks (0.1.0)
4
+ prizepicks (0.2.0)
5
5
  faraday
6
6
  faraday-cookie_jar
7
7
 
data/README.md CHANGED
@@ -1,31 +1,49 @@
1
- # Prizepicks
1
+ PrizePicks Client
2
+ =================
2
3
 
3
- TODO: Delete this and the text below, and describe your gem
4
+ [![Gem Version](https://badge.fury.io/rb/prizepicks.svg)](https://badge.fury.io/rb/prizepicks)
5
+ [![Run tests](https://github.com/troyizzle/prizepicks/actions/workflows/main.yml/badge.svg)](https://github.com/troyizzle/prizepicks/actions/workflows/main.yml)
4
6
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/prizepicks`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+ A client for PrizePicks API.
6
8
 
7
9
  ## Installation
8
10
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
11
+ Add this line to your application's Gemfile:
12
+ ```ruby
13
+ gem 'prizepicks'
14
+ ```
10
15
 
11
- Install the gem and add to the application's Gemfile by executing:
16
+ Add then execute:
12
17
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+ `$ bundle install`
14
19
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
20
+ Or install it yourself as:
16
21
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
22
+ `$ gem install prizepicks`
18
23
 
19
24
  ## Usage
25
+ ### Currently this only has fetching /entries
20
26
 
21
- TODO: Write usage instructions here
27
+ ```
28
+ client = PrizePicks::Client.new({
29
+ email: example@example.com,
30
+ password: foobar
31
+ })
22
32
 
23
- ## Development
33
+ client.sign_in
34
+ client.entries
35
+ ```
24
36
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+ ## Development
26
38
 
27
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+ Run `bin/setup` to install dependencies. Then, run `rake test` to verify the test. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
40
 
29
41
  ## Contributing
30
42
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/prizepicks.
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/troyizzle/prizepicks.
44
+
45
+ This project is early in progress, very early.
46
+
47
+ ## License
48
+
49
+ This gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -3,8 +3,14 @@ module PrizePicks
3
3
  module Api
4
4
  module Endpoints
5
5
  module Entries
6
+ ENDPOINT = '/v1/entries'
7
+
6
8
  def entries(options = {})
7
- request(:get, 'v1/entries', options)
9
+ raise ArgumentError, 'email is required' unless @email
10
+ raise ArgumentError, 'password is required' unless @password
11
+
12
+ resp = request(:get, ENDPOINT, options)
13
+ Collection.from_response(resp, type: Entry)
8
14
  end
9
15
  end
10
16
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ module Api
4
+ module Endpoints
5
+ module Leagues
6
+ ENDPOINT = '/v1/leagues'
7
+
8
+ def leagues(options = {})
9
+ resp = request(:get, ENDPOINT, options)
10
+ Collection.from_response(resp, type: League)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ module Api
4
+ module Endpoints
5
+ module Projections
6
+ ENDPOINT = '/v1/projections'
7
+
8
+ def projections(options = {})
9
+ resp = request(:get, ENDPOINT, options)
10
+ Collection.from_response(resp, type: Projection)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,15 +1,20 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module PrizePicks
3
4
  module Api
4
5
  module Endpoints
5
6
  module SignIn
7
+ ENDPOINT = '/users/sign_in'
8
+
6
9
  def sign_in
7
- request(:post, '/users/sign_in', {
10
+ resp = request(:post, ENDPOINT, {
8
11
  user: {
9
12
  email: @email,
10
13
  password: @password,
11
14
  },
12
15
  })
16
+
17
+ User.new(resp)
13
18
  end
14
19
  end
15
20
  end
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'endpoints/entries'
4
+ require_relative 'endpoints/leagues'
5
+ require_relative 'endpoints/projections'
4
6
  require_relative 'endpoints/sign_in'
5
7
 
6
8
  module PrizePicks
7
9
  module Api
8
10
  module Endpoints
9
11
  include Entries
12
+ include Leagues
13
+ include Projections
10
14
  include SignIn
11
15
  end
12
16
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ module Api
4
+ module Responses
5
+ class User < OpenStruct
6
+ def initialize(attributes)
7
+ super to_obstruct(attributes)
8
+ end
9
+
10
+ def to_obstruct(_attributes)
11
+ case obj
12
+ when Hash
13
+ OpenStruct.new(obj.transform_values { |val| to_obstruct(val) })
14
+ when Array
15
+ obj.map { |o| to_obstruct(o) }
16
+ else
17
+ obj
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -6,14 +6,16 @@ module PrizePicks
6
6
  include Api::Endpoints
7
7
 
8
8
  attr_accessor(*Config::ATTRIBUTES)
9
+ attr_reader :adapter
9
10
 
10
11
  def initialize(options = {})
11
12
  PrizePicks::Config::ATTRIBUTES.each do |key|
12
13
  send("#{key}=", options.fetch(key, PrizePicks.config.send(key)))
13
14
  end
14
15
 
15
- raise ArgumentError, 'Missing :email' unless email
16
- raise ArgumentError, 'Missing :password' unless password
16
+ # For testing
17
+ @stubs = options[:stubs] || nil
18
+ @adapter = options[:adapter] || nil
17
19
  end
18
20
  end
19
21
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ class Collection
4
+ attr_reader :data, :total_pages, :current_page
5
+
6
+ def self.from_response(response, type:)
7
+ new(
8
+ data: response['data'].map { |attrs| type.new(attrs) },
9
+ current_page: response.dig('meta', 'current_page'),
10
+ total_pages: response.dig('meta', 'total_pages')
11
+ )
12
+ end
13
+
14
+ def initialize(data:, current_page:, total_pages:)
15
+ @data = data
16
+ @current_page = current_page
17
+ @total_pages = total_pages
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ class Error < StandardError; end
4
+ end
@@ -10,7 +10,7 @@ module PrizePicks
10
10
  faraday.response :json
11
11
  faraday.use :cookie_jar
12
12
  faraday.response :raise_error
13
- faraday.adapter ::Faraday.default_adapter
13
+ faraday.adapter adapter, @stubs
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require 'ostruct'
3
+
4
+ module PrizePicks
5
+ class Base < OpenStruct
6
+ def initialize(resp)
7
+ @resp = resp
8
+ super to_obstruct(resp.dig('data', 'attributes'))
9
+ end
10
+
11
+ def data
12
+ @resp['data']
13
+ end
14
+
15
+ def to_obstruct(obj)
16
+ case obj
17
+ when Hash
18
+ OpenStruct.new(obj.transform_values { |val| to_obstruct(val) })
19
+ when Array
20
+ obj.map { |o| to_obstruct(o) }
21
+ else
22
+ obj
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ class Entry < Base
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ class League < Base
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ class Projection < Base
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ module PrizePicks
3
+ class User < Base
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrizePicks
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/prizepicks.rb CHANGED
@@ -1,17 +1,26 @@
1
1
  # frozen_string_literal: true
2
-
3
- require 'prizepicks/version'
4
- require 'prizepicks/config'
5
-
6
2
  require 'faraday'
7
3
  require 'faraday-cookie_jar'
8
-
4
+ require 'prizepicks/version'
5
+ # require 'prizepicks/config'
9
6
  require_relative 'prizepicks/faraday/connection'
10
7
  require_relative 'prizepicks/faraday/request'
11
8
  require_relative 'prizepicks/api/endpoints'
12
- require_relative 'prizepicks/client'
9
+ # require_relative 'prizepicks/client'
10
+
11
+ module PrizePicks
12
+ autoload :Client, 'prizepicks/client'
13
+ autoload :Collection, 'prizepicks/collection'
14
+ autoload :Config, 'prizepicks/config'
15
+ autoload :Error, 'prizepicks/error'
16
+
17
+ # Responses
18
+ autoload :Responses, 'prizepicks/api/responses'
13
19
 
14
- # module Prizepicks
15
- # class Error < StandardError; end
16
- # # Your code goes here...
17
- # end
20
+ # Object
21
+ autoload :Base, 'prizepicks/objects/base'
22
+ autoload :Entry, 'prizepicks/objects/entry'
23
+ autoload :League, 'prizepicks/objects/league'
24
+ autoload :Projection, 'prizepicks/objects/projection'
25
+ autoload :User, 'prizepicks/objects/user'
26
+ end
data/sig/prizepicks.rbs CHANGED
@@ -1,4 +1,4 @@
1
- module Prizepicks
1
+ module PrizePicks
2
2
  VERSION: String
3
3
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prizepicks
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
  - Troy Underwood
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-17 00:00:00.000000000 Z
11
+ date: 2023-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".rubocop.yml"
105
+ - CHANGELOG.md
105
106
  - Gemfile
106
107
  - Gemfile.lock
107
108
  - README.md
@@ -109,11 +110,21 @@ files:
109
110
  - lib/prizepicks.rb
110
111
  - lib/prizepicks/api/endpoints.rb
111
112
  - lib/prizepicks/api/endpoints/entries.rb
113
+ - lib/prizepicks/api/endpoints/leagues.rb
114
+ - lib/prizepicks/api/endpoints/projections.rb
112
115
  - lib/prizepicks/api/endpoints/sign_in.rb
116
+ - lib/prizepicks/api/responses/user.rb
113
117
  - lib/prizepicks/client.rb
118
+ - lib/prizepicks/collection.rb
114
119
  - lib/prizepicks/config.rb
120
+ - lib/prizepicks/error.rb
115
121
  - lib/prizepicks/faraday/connection.rb
116
122
  - lib/prizepicks/faraday/request.rb
123
+ - lib/prizepicks/objects/base.rb
124
+ - lib/prizepicks/objects/entry.rb
125
+ - lib/prizepicks/objects/league.rb
126
+ - lib/prizepicks/objects/projection.rb
127
+ - lib/prizepicks/objects/user.rb
117
128
  - lib/prizepicks/version.rb
118
129
  - sig/prizepicks.rbs
119
130
  homepage: https://github.com/troyizzle/prizepicks
@@ -121,6 +132,7 @@ licenses: []
121
132
  metadata:
122
133
  homepage_uri: https://github.com/troyizzle/prizepicks
123
134
  source_code_uri: https://github.com/troyizzle/prizepicks
135
+ changelog_uri: https://github.com/troyizzle/prizepicks/blob/master/CHANGELOG.md
124
136
  post_install_message:
125
137
  rdoc_options: []
126
138
  require_paths:
@@ -136,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
148
  - !ruby/object:Gem::Version
137
149
  version: '0'
138
150
  requirements: []
139
- rubygems_version: 3.4.5
151
+ rubygems_version: 3.2.3
140
152
  signing_key:
141
153
  specification_version: 4
142
154
  summary: PrizePicks client