Class: Yelp::Web
- Inherits:
-
Object
- Object
- Yelp::Web
- 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
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#body ⇒ Object
Returns the value of attribute body.
-
#city ⇒ Object
Returns the value of attribute city.
-
#consumer ⇒ Object
Returns the value of attribute consumer.
Class Method Summary collapse
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/yelp/web.rb', line 5 def access_token @access_token end |
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/yelp/web.rb', line 5 def body @body end |
#city ⇒ Object
Returns the value of attribute city.
5 6 7 |
# File 'lib/yelp/web.rb', line 5 def city @city end |
#consumer ⇒ Object
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.login( params ) login_valid = 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 login_form = agent.page.form_with( id: 'login-form' ) if login_form login_form.email = email login_form.password = password login_form.submit login_valid = agent.page.link_with( id: 'logout-link') != nil end login_valid ? MSG[:success] : MSG[:failed] rescue Net::HTTP::Persistent::Error => e MSG[:connection_error] end |