Class: BptScraper::PullFeed

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/bpt_scraper/pull_feed.rb

Overview

Handles the fetching of data from BPTs API

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#failed_login_fetch, #failed_login_post, #missing_options_error, #missing_parameters_error, #no_developer_id_error

Constructor Details

#initialize(developer_id: nil, client: nil) ⇒ PullFeed

Returns a new instance of PullFeed.



10
11
12
13
14
# File 'lib/bpt_scraper/pull_feed.rb', line 10

def initialize(developer_id: nil, client: nil)
  self.developer_id = developer_id || self.class.developer_id
  self.client = client || self.class.client
  no_developer_id_error if self.developer_id.nil?
end

Class Attribute Details

.clientObject

Returns the value of attribute client.



102
103
104
# File 'lib/bpt_scraper/pull_feed.rb', line 102

def client
  @client
end

.developer_idObject

Returns the value of attribute developer_id.



102
103
104
# File 'lib/bpt_scraper/pull_feed.rb', line 102

def developer_id
  @developer_id
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/bpt_scraper/pull_feed.rb', line 8

def client
  @client
end

#developer_idObject

Returns the value of attribute developer_id.



8
9
10
# File 'lib/bpt_scraper/pull_feed.rb', line 8

def developer_id
  @developer_id
end

Class Method Details

.resetObject



96
97
98
99
# File 'lib/bpt_scraper/pull_feed.rb', line 96

def self.reset
  self.developer_id = nil
  self.client = nil
end

Instance Method Details

#account_url_builder(endpoint) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/bpt_scraper/pull_feed.rb', line 82

def (endpoint)
  base_url = "https://www.brownpapertickets.com/api2/#{endpoint}?id=#{developer_id}"
  base_url += "&account=#{client}" unless client.nil?
  base_url += "&event_id=#{@event_id}" unless @event_id.nil?
  base_url += "&date_id=#{@date_id}" unless @date_id.nil?
  base_url += "&price_id=#{@price_id}" unless @price_id.nil?
  base_url += "&current=1" if @only_current
  base_url
end

#date_list(event_id: nil, date_id: nil) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/bpt_scraper/pull_feed.rb', line 24

def date_list(event_id: nil, date_id: nil)
  missing_parameters_error('PullFeed', 'event_id') if event_id.nil?
  @event_id = event_id
  @date_id = date_id
  url = list_url_builder('datelist')
  response = fetch_url url
  response
end

#date_sales(event_id: nil, date_id: nil) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/bpt_scraper/pull_feed.rb', line 53

def date_sales(event_id: nil, date_id: nil)
  missing_parameters_error('PullFeed', 'client') if client.nil?
  missing_parameters_error('PullFeed', 'event_id') if event_id.nil?
  @event_id = event_id
  @date_id = date_id
  url = ('datesales')
  response = fetch_url url
  response
end

#event_list(event_id: nil) ⇒ Object

returns an HTTParty response object



17
18
19
20
21
22
# File 'lib/bpt_scraper/pull_feed.rb', line 17

def event_list(event_id: nil)
  @event_id = event_id
  url = list_url_builder('eventlist')
  response = fetch_url url
  response
end

#event_sales(event_id: nil, current: nil) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/bpt_scraper/pull_feed.rb', line 44

def event_sales(event_id: nil, current: nil)
  missing_parameters_error('PullFeed', 'client') if client.nil?
  @event_id = event_id
  @current = current
  url = ('eventsales')
  response = fetch_url url
  response
end

#fetch_url(url) ⇒ Object



92
93
94
# File 'lib/bpt_scraper/pull_feed.rb', line 92

def fetch_url(url)
  HTTParty.get(url)
end

#list_url_builder(endpoint) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/bpt_scraper/pull_feed.rb', line 73

def list_url_builder(endpoint)
  base_url = "https://www.brownpapertickets.com/api2/#{endpoint}?id=#{developer_id}"
  base_url += "&client=#{client}" unless client.nil?
  base_url += "&event_id=#{@event_id}" unless @event_id.nil?
  base_url += "&date_id=#{@date_id}" unless @date_id.nil?
  base_url += "&price_id=#{@price_id}" unless @price_id.nil?
  base_url
end

#order_list(event_id: nil, date_id: nil) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/bpt_scraper/pull_feed.rb', line 63

def order_list(event_id: nil, date_id: nil)
  missing_parameters_error('PullFeed', 'client') if client.nil?
  missing_parameters_error('PullFeed', 'event_id') if event_id.nil?
  @event_id = event_id
  @date_id = date_id
  url = ('orderlist')
  response = fetch_url url
  response
end

#price_list(event_id: nil, date_id: nil, price_id: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/bpt_scraper/pull_feed.rb', line 33

def price_list(event_id: nil, date_id: nil, price_id: nil)
  missing_parameters_error('PullFeed', 'event_id') if event_id.nil?
  missing_parameters_error('PullFeed', 'date_id') if date_id.nil?
  @event_id = event_id
  @date_id = date_id
  @price_id = price_id
  url = list_url_builder('pricelist')
  response = fetch_url url
  response
end