Class: Flowdock::Client
- Inherits:
-
Object
show all
- Includes:
- Helpers, HTTParty
- Defined in:
- lib/flowdock.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#blank?, #handle_response
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
133
134
135
136
|
# File 'lib/flowdock.rb', line 133
def initialize(options = {})
@api_token = options[:api_token]
raise InvalidParameterError, "Client must have :api_token attribute" if blank?(@api_token)
end
|
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
132
133
134
|
# File 'lib/flowdock.rb', line 132
def api_token
@api_token
end
|
Instance Method Details
#chat_message(params) ⇒ Object
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/flowdock.rb', line 138
def chat_message(params)
raise InvalidParameterError, "Message must have :content" if blank?(params[:content])
raise InvalidParameterError, "Message must have :flow" if blank?(params[:flow])
params = params.clone
tags = (params[:tags].kind_of?(Array)) ? params[:tags] : []
params[:message] = params.delete(:message_id) if params[:message_id]
tags.reject! { |tag| !tag.kind_of?(String) || blank?(tag) }
event = if params[:message] then 'comment' else 'message' end
post(event + 's', params.merge(tags: tags, event: event))
end
|
#delete(path) ⇒ Object
164
165
166
167
|
# File 'lib/flowdock.rb', line 164
def delete(path)
resp = self.class.delete(api_url(path), :basic_auth => {:username => @api_token, :password => ''}, :headers => )
handle_response(resp)
end
|
#get(path, data = {}) ⇒ Object
154
155
156
157
|
# File 'lib/flowdock.rb', line 154
def get(path, data = {})
resp = self.class.get(api_url(path), :query => data, :basic_auth => {:username => @api_token, :password => ''}, :headers => )
handle_response(resp)
end
|
#post(path, data = {}) ⇒ Object
149
150
151
152
|
# File 'lib/flowdock.rb', line 149
def post(path, data = {})
resp = self.class.post(api_url(path), :body => MultiJson.dump(data), :basic_auth => {:username => @api_token, :password => ''}, :headers => )
handle_response(resp)
end
|
#put(path, data = {}) ⇒ Object
159
160
161
162
|
# File 'lib/flowdock.rb', line 159
def put(path, data = {})
resp = self.class.put(api_url(path), :body => MultiJson.dump(data), :basic_auth => {:username => @api_token, :password => ''}, :headers => )
handle_response(resp)
end
|