Class: WWW::Wassr
- Inherits:
-
Object
- Object
- WWW::Wassr
- Defined in:
- lib/wassruby.rb
Constant Summary collapse
- WASSR =
"api.wassr.jp"
- WASSR_RUBY =
"Wassruby"
- WASSR_API_URL =
{ :UPDATE => "/statuses/update.json?status=", :PUBLIC_TIMELINE => "/statuses/public_timeline.json", :USER_TIMELINE => "/statuses/user_timeline.json?id=", :USER_SHOW => "/statuses/show.json?id=", :NEW_CHANNEL => "/channel/list.rss", :CHANNEL_CHECK => "/channel/exists.json?name_en=", :USER_CHANNEL_LIST => "/channel_user/user_list.json?login_id=", :SL_TIMELINE => "/statuses/sl_timeline.json", :TODO_UPDATE => "/todo/add.json?body=", :TODO_LIST => "/todo/list.json?page=1&done_fg=0", }
Class Method Summary collapse
- .get(key, id = nil) ⇒ Object
- .get_body(api_add, id = "") ⇒ Object
- .get_res_body_json(api_add, id = "") ⇒ Object
- .get_res_body_rss(api_add, id = "") ⇒ Object
- .start(login_id, password, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(login_id, password) ⇒ Wassr
constructor
A new instance of Wassr.
- #post(key, val = "") ⇒ Object
- #post!(api_key, val) ⇒ Object
Constructor Details
Class Method Details
.get(key, id = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wassruby.rb', line 53 def get(key, id=nil) case key when :public_timeline get_res_body_json(:PUBLIC_TIMELINE) when :user_timeline get_res_body_json(:USER_TIMELINE, id) if id != nil when :user_show #get new one message of user get_res_body_json(:USER_SHOW, id) if id != nil when :new_channel get_res_body_rss(:NEW_CHANNEL) when :channel_check get_res_body_json(:CHANNEL_CHECK, id) if id != nil when :sl_timeline get_res_body_json(:SL_TIMELINE) when :user_channel_list get_res_body_json(:USER_CHANNEL_LIST, id) if id != nil when :todo_list get_res_body_json(:TODO_LIST) end end |
.get_body(api_add, id = "") ⇒ Object
41 42 43 |
# File 'lib/wassruby.rb', line 41 def get_body(api_add, id="") Net::HTTP.new(WASSR, 80).get(WASSR_API_URL[api_add] << id).body end |
.get_res_body_json(api_add, id = "") ⇒ Object
45 46 47 |
# File 'lib/wassruby.rb', line 45 def get_res_body_json(api_add, id="") JSON.parse(get_body(api_add, id)) end |
.get_res_body_rss(api_add, id = "") ⇒ Object
49 50 51 |
# File 'lib/wassruby.rb', line 49 def get_res_body_rss(api_add, id="") RSS::Parser.parse(get_body(api_add, id)) end |
Instance Method Details
#post(key, val = "") ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/wassruby.rb', line 82 def post(key, val="") case key when :update post!(:UPDATE, val) when :todo_update post!(:TODO_UPDATE, val) end end |
#post!(api_key, val) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/wassruby.rb', line 75 def post!(api_key, val) req = Net::HTTP::Post.new(WASSR_API_URL[api_key] << CGI.escape(val) << "&source=" << WASSR_RUBY) req.basic_auth(@login_id, @password) res = @http.request(req) end |