Class: SyoboiCalendar::Agent
- Inherits:
-
Object
- Object
- SyoboiCalendar::Agent
- Defined in:
- lib/syoboi_calendar/agent.rb
Constant Summary collapse
- BASE_URL =
"http://cal.syoboi.jp"
- SEARCH_URL =
BASE_URL + "/find"
- JSON_URL =
BASE_URL + "/json.php"
- LOGIN_URL =
BASE_URL + "/usr"
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Agent
constructor
login is option to search with user channel setting.
- #json(query) ⇒ Object
- #login(user, pass) ⇒ Object
- #login? ⇒ Boolean
- #search(query) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Agent
login is option to search with user channel setting
12 13 14 15 16 |
# File 'lib/syoboi_calendar/agent.rb', line 12 def initialize(opts = {}) if opts[:user] && opts[:pass] login(opts[:user], opts[:pass]) end end |
Instance Method Details
#json(query) ⇒ Object
31 32 33 34 |
# File 'lib/syoboi_calendar/agent.rb', line 31 def json(query) page = get JSON_URL, query JSON.parse(page.content) end |
#login(user, pass) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/syoboi_calendar/agent.rb', line 18 def login(user, pass) page = get LOGIN_URL form = page.forms[1] form.usr = user form.pass = pass mechanize.submit(form) @logined = true end |
#login? ⇒ Boolean
27 28 29 |
# File 'lib/syoboi_calendar/agent.rb', line 27 def login? !!@logined end |
#search(query) ⇒ Object
36 37 38 |
# File 'lib/syoboi_calendar/agent.rb', line 36 def search(query) get SEARCH_URL, query end |