Class: Epicmix::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/epicmix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Client

Initializes and logs in to Epicmix



11
12
13
14
# File 'lib/epicmix.rb', line 11

def initialize(username, password)
  @username, @password = username, password
  @token = 
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#headers(extra = {}) ⇒ Object

Sets headers



42
43
44
45
46
47
# File 'lib/epicmix.rb', line 42

def headers(extra = {})
  extra.merge 'Cookie' => [session_id, website, session_id].join('; '),
    'Accept-Encoding' => 'gzip',
    'User-Agent' => 'EpicMix 15880 rv:2.1 (iPhone; iPhone OS 5.0.1; en_US)',
    'Host' => 'www.epicmix.com'
end

#loginObject

Login to epic mix



17
18
19
20
21
22
23
24
# File 'lib/epicmix.rb', line 17

def 
  url = 'https://www.epicmix.com/vailresorts/sites/epicmix/api/mobile/authenticate.ashx'

  options = { :query => { :loginID => username, :password => password }}
  response = HTTParty.post(url, options)

  token_from(response) # if response.instance_of? Net::HTTPOK
end

#season_statsObject

Gets all your season stats



27
28
29
30
31
32
33
34
# File 'lib/epicmix.rb', line 27

def season_stats
  url = 'https://www.epicmix.com/vailresorts/sites/epicmix/api/mobile/userstats.ashx'

  options = { :timetype => 'season', :token => token }
  response = HTTParty.get(url, :query => options, :headers => headers)

  JSON.parse(response.body)['seasonStats']
end

#session_idObject

Get the sesson id, to be inserted into the cookies in the header



50
51
52
# File 'lib/epicmix.rb', line 50

def session_id
  "ASP.NET_SessionId=#{token}"
end

#token_from(response) ⇒ Object

Gets token out of response cookies



37
38
39
# File 'lib/epicmix.rb', line 37

def token_from(response)
  response.headers['Set-Cookie'][%r{ASP.NET_SessionId=([^;]+);}, 1]
end

#websiteObject



54
55
56
# File 'lib/epicmix.rb', line 54

def website
  "website#sc_wede=1"
end