Class: Flowdock::Client

Inherits:
Object
  • 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_tokenObject (readonly)

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



176
177
178
179
# File 'lib/flowdock.rb', line 176

def delete(path)
  resp = self.class.delete(api_url(path), :basic_auth => {:username => @api_token, :password => ''}, :headers => headers)
  handle_response(resp)
end

#get(path, data = {}) ⇒ Object



166
167
168
169
# File 'lib/flowdock.rb', line 166

def get(path, data = {})
  resp = self.class.get(api_url(path), :query => data, :basic_auth => {:username => @api_token, :password => ''}, :headers => headers)
  handle_response(resp)
end

#post(path, data = {}) ⇒ Object



161
162
163
164
# File 'lib/flowdock.rb', line 161

def post(path, data = {})
  resp = self.class.post(api_url(path), :body => MultiJson.dump(data), :basic_auth => {:username => @api_token, :password => ''}, :headers => headers)
  handle_response(resp)
end

#private_message(params) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/flowdock.rb', line 149

def private_message(params)
  raise InvalidParameterError, "Message must have :content" if blank?(params[:content])
  raise InvalidParameterError, "Message must have :user_id" if blank?(params[:user_id])

  user_id = params.delete(:user_id)
  
  params = params.clone
  event = "message"

  post("private/#{user_id}/messages", params.merge(event: event))
end

#put(path, data = {}) ⇒ Object



171
172
173
174
# File 'lib/flowdock.rb', line 171

def put(path, data = {})
  resp = self.class.put(api_url(path), :body => MultiJson.dump(data), :basic_auth => {:username => @api_token, :password => ''}, :headers => headers)
  handle_response(resp)
end