Class: SodaXmlTeam::Address
- Defined in:
- lib/soda_xml_team/address.rb
Class Method Summary collapse
Methods inherited from Client
#content_finder, #get_document, #get_listing, #initialize
Constructor Details
This class inherits a constructor from SodaXmlTeam::Client
Class Method Details
.build(method, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/soda_xml_team/address.rb', line 4 def self.build(method, = {}) path = [] if !["get_listing", "get_document"].include? method raise "Invalid method." end # Get a listing of documents if method === 'get_listing' endpoint = '/getListings?' if [:league_id].nil? && [:team_id].nil? raise "Must specify a `league_id` (league-keys) or `team_id` (team-keys)." end # League identifier if [:league_id] path << "league-keys=#{options[:league_id]}" end # Team identifier if [:team_id] path << "team-keys=#{options[:team_id]}" end # Document type if [:type] path << "fixture-keys=#{options[:type]}" else raise "Must specify the `type` (fixture-keys)" end # Start date/time if [:start_datetime].is_a? DateTime path << "earliest-date-time=#{options[:start_datetime].strftime('%Y%m%dT%H%M%S%z')}" end # End date/time if [:end_datetime].is_a? DateTime path << "latest-date-time=#{options[:end_datetime].strftime('%Y%m%dT%H%M%S%z')}" end # Use a date window if [:hours].is_a? Numeric path << "date-window=#{options[:hours]}00" end # Limit the number of listings returned returned if ![:limit].nil? && [:limit] > 0 && [:limit] <= 50 path << "max-result-count=#{options[:limit]}" else path << "max-result-count=10" end # Priority if [:priority] path << "priorities=#{options[:priority]}" end # Which document revisions to return if [:revisions] === 'all' path << "revision-control=all" else path << "revision-control=latest-only" end # Always return the XML listing path << "stylesheet=sportsml2rss-1.0-s" # Get a specific document else endpoint = '/getDocuments?' if [:document_id] path << "doc-ids=#{options[:document_id]}" else raise "Missing `document_id` (doc-ids)" end end # Concatenate it together path = path.join "&" # Use sandbox hostname or production if [:sandbox] === true return SodaXmlTeam::API_SANDBOX_URL + endpoint + path else return SodaXmlTeam::API_BASE_URL + endpoint + path end end |