Class: YFantasy::Api::UrlBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/y_fantasy/api/url_builder.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

BASE_URL =

invalid urls:

/games;game_keys=79/league/31399
/games;game_keys=79/league/79.l.31399
/game/79/league/79.l.31399
/game/79/league/31399
"https://fantasysports.yahooapis.com/fantasy/v2"
CURRENT_USER_URL =
"#{BASE_URL}/users;use_login=1"

Instance Method Summary collapse

Constructor Details

#initialize(resource, keys: [], game_codes: [], subresources: [], **options) ⇒ UrlBuilder

Returns a new instance of UrlBuilder.



24
25
26
27
28
29
30
31
# File 'lib/y_fantasy/api/url_builder.rb', line 24

def initialize(resource, keys: [], game_codes: [], subresources: [], **options)
  @options = options
  @url = options[:scope_to_user] ? CURRENT_USER_URL.dup : BASE_URL.dup
  @resource = override_resource(resource.to_s)
  @keys = Array(keys).map(&:to_s)
  @game_codes = Array(game_codes).map(&:to_s)
  @subresources = Array(subresources)
end

Instance Method Details

#buildObject



33
34
35
36
37
38
39
40
# File 'lib/y_fantasy/api/url_builder.rb', line 33

def build
  validate_args!
  singular_resource? ? build_resource_url : build_collection_url
  return @url if @subresources.empty?

  params = SubresourceParamBuilder.new(@subresources, **@options).build
  @url.concat(params)
end