Class: JavaEye::Client
- Inherits:
-
Object
- Object
- JavaEye::Client
- Defined in:
- lib/javaeye/client.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #create_chat(body, option = {}) ⇒ Object
- #get_all(option = {}) ⇒ Object
- #get_chats(url, option) ⇒ Object
- #get_list(option = {}) ⇒ Object
- #get_reply(option = {}) ⇒ Object
- #get_request(url, option = {}) ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
- #post_request(url, data, option = {}) ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/javaeye/client.rb', line 6 def initialize(username, password) @username = username @password = password end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/javaeye/client.rb', line 4 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/javaeye/client.rb', line 3 def username @username end |
Instance Method Details
#create_chat(body, option = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/javaeye/client.rb', line 69 def create_chat(body, option={}) chat = {} chat[:body] = body chat[:reply_id] = option[:reply_id] ? option[:reply_id] : nil chat[:via] = JavaEye::VIA resp = post_request(URL[:create],chat) if resp.code == '200' chat else nil end end |
#get_all(option = {}) ⇒ Object
65 66 67 |
# File 'lib/javaeye/client.rb', line 65 def get_all(option = {}) get_chats(URL[:all], option) end |
#get_chats(url, option) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/javaeye/client.rb', line 46 def get_chats(url,option) resp = get_request(url, option) if resp.code == "200" chats ||= [] JSON.parse(resp.body).each do |chat| chats << Chat.new(chat) end end chats end |
#get_list(option = {}) ⇒ Object
57 58 59 |
# File 'lib/javaeye/client.rb', line 57 def get_list(option = {}) get_chats(URL[:list], option) end |
#get_reply(option = {}) ⇒ Object
61 62 63 |
# File 'lib/javaeye/client.rb', line 61 def get_reply(option = {}) get_chats(URL[:reply], option) end |
#get_request(url, option = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/javaeye/client.rb', line 23 def get_request(url,option={}) url = JavaEye::get_request_uri(url,option) url = URI.parse(url) Net::HTTP.start(url.host) do |http| req = Net::HTTP::Get.new(url.request_uri) req.basic_auth @username, @password resp = http.request(req) return resp end end |
#post_request(url, data, option = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/javaeye/client.rb', line 34 def post_request(url,data,option={}) url = JECoat::get_request_uri(url,option) url = URI.parse(url) Net::HTTP.start(url.host) do |http| req = Net::HTTP::Post.new(url.request_uri) req.basic_auth @username, @password req.set_form_data(data) resp = http.request(req) return resp end end |
#verify ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/javaeye/client.rb', line 11 def verify resp = get_request(URL[:auth]) case resp.code when "200" true when "400" false when "401" false end end |