Created
October 25, 2012 19:56
-
-
Save gnab/3955025 to your computer and use it in GitHub Desktop.
GuleSider Min Side Ruby wrapper for sending SMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'mechanize' | |
class GuleSider | |
class NotLoggedInError < StandardError; end | |
def self.log_in(username, password) | |
agent = Mechanize.new | |
agent.ca_file = '/usr/lib/ssl/certs/ca-certificates.crt' | |
page = agent.get('https://www.gulesider.no/mypage/loginPopupForm.c') | |
form = page.form_with(:action => '/mypage/login.c') | |
form.field_with(:name => 'username').value = username | |
form.field_with(:name => 'password').value = password | |
@@page = form.submit | |
end | |
def self.send_sms(recipients, text) | |
throw NotLoggedInError.new unless defined?(@@page) | |
frame = @@page.iframe_with(:src => '/mypage/sendSmsInline.c').content | |
form = frame.form_with(:action => '/mypage/sendSmsInline.c') | |
form.field_with(:id => 'mobnr').value = recipients | |
form.field_with(:id => 'smstxt').value = text | |
form.submit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment