Class: Yelp::Web

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

Constant Summary collapse

LOGIN_PAGE =
'http://yelp.co.uk/login'
MSG =
{
success: 'Your account details are valid',
failed: 'Failed to log in to Yelp',
connection_error: 'Could not connect to the internet' }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



5
6
7
# File 'lib/yelp/web.rb', line 5

def access_token
  @access_token
end

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/yelp/web.rb', line 5

def body
  @body
end

#cityObject

Returns the value of attribute city.



5
6
7
# File 'lib/yelp/web.rb', line 5

def city
  @city
end

#consumerObject

Returns the value of attribute consumer.



5
6
7
# File 'lib/yelp/web.rb', line 5

def consumer
  @consumer
end

Class Method Details

.login(params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yelp/web.rb', line 14

def self.( params )
   = false
  email, password = params[:username], params[:password]
  #using mechanize in order to post csrftoken param
  agent = Mechanize.new { |a| a.user_agent_alias = 'Mac Safari' }
  agent.get( LOGIN_PAGE )

  #extract login-form
   = agent.page.form_with( id: 'login-form' )
  if 
    .email = email
    .password = password
    .submit
     = agent.page.link_with( id: 'logout-link') != nil
  end

   ? MSG[:success] : MSG[:failed]
rescue Net::HTTP::Persistent::Error => e
  MSG[:connection_error]
end