Class: Shutwork::Client
- Inherits:
-
Object
- Object
- Shutwork::Client
- Defined in:
- lib/shutwork/client.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #file(room_id, file_id) ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #me ⇒ Object
- #process(res) ⇒ Object
- #room_files(room_id) ⇒ Object
- #room_members(room_id) ⇒ Object
- #room_messages(room_id) ⇒ Object
- #rooms ⇒ Object
- #verify!(res) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shutwork/client.rb', line 10 def initialize opts = {} @base_url = opts[:base_url] || "https://api.chatwork.com/v2/" @token = opts[:token] @verbose = opts[:verbose] @conn = Faraday.new( url: @base_url, headers: { "X-ChatWorkToken" => @token } ) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/shutwork/client.rb', line 8 def base_url @base_url end |
Instance Method Details
#file(room_id, file_id) ⇒ Object
42 43 44 |
# File 'lib/shutwork/client.rb', line 42 def file room_id, file_id process @conn.get("rooms/#{room_id}/files/#{file_id}?create_download_url=1") end |
#me ⇒ Object
22 23 24 |
# File 'lib/shutwork/client.rb', line 22 def me process @conn.get("me") end |
#process(res) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/shutwork/client.rb', line 46 def process res if @verbose $stderr.puts res.headers.to_json end verify! res res.body end |
#room_files(room_id) ⇒ Object
38 39 40 |
# File 'lib/shutwork/client.rb', line 38 def room_files room_id process @conn.get("rooms/#{room_id}/files") end |
#room_members(room_id) ⇒ Object
34 35 36 |
# File 'lib/shutwork/client.rb', line 34 def room_members room_id process @conn.get("rooms/#{room_id}/members") end |
#room_messages(room_id) ⇒ Object
30 31 32 |
# File 'lib/shutwork/client.rb', line 30 def room_id process @conn.get("rooms/#{room_id}/messages?force=1") end |
#rooms ⇒ Object
26 27 28 |
# File 'lib/shutwork/client.rb', line 26 def rooms process @conn.get("rooms") end |