class Mypeople::Client

Constants

APIS

Public Class Methods

new(attrs = {}) click to toggle source
# File lib/mypeople/client.rb, line 54
def initialize(attrs = {})
  self.configuration.attributes = attrs
end

Public Instance Methods

buddy_profile(buddy_id) click to toggle source
# File lib/mypeople/client.rb, line 118
def buddy_profile(buddy_id)
  method = APIS[:buddy_profile][:method]
  path = APIS[:buddy_profile][:path]
  data = {
    "buddyId" => buddy_id
  }

  request(method, path, data)
end
configuration() click to toggle source
# File lib/mypeople/client.rb, line 62
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/mypeople/client.rb, line 58
def configure
  yield configuration if block_given?
end
download_file(file_id) click to toggle source
# File lib/mypeople/client.rb, line 159
def download_file(file_id)
  method = APIS[:download_file][:method]
  path = APIS[:download_file][:path]
  data = {
    "fileId" => file_id
  }

  request(method, path, data, false)
end
exit_from_group(group_id) click to toggle source
# File lib/mypeople/client.rb, line 149
def exit_from_group(group_id)
  method = APIS[:exit_from_group][:method]
  path = APIS[:exit_from_group][:path]
  data = {
    "groupId" => group_id
  }

  request(method, path, data)
end
get(http, path, data, json) click to toggle source
# File lib/mypeople/client.rb, line 78
def get(http, path, data, json)
  data = URI.encode_www_form(data)
  resp, body = http.send_request("GET", "#{path}?#{data}")

  if json
    JSON.parse(resp.body)
  else
    resp.body
  end
end
get_members(group_id) click to toggle source
# File lib/mypeople/client.rb, line 128
def get_members(group_id)
  method = APIS[:get_members][:method]
  path = APIS[:get_members][:path]
  data = {
    "groupId" => group_id
  }

  request(method, path, data)
end
post(http, path, data, json) click to toggle source
# File lib/mypeople/client.rb, line 89
def post(http, path, data, json)
  data = URI.encode_www_form(data)
  resp, body = http.send_request("POST", path, data)

  if json
    JSON.parse(resp.body)
  else
    resp.body
  end
end
request(method, path, data, json = true) click to toggle source
# File lib/mypeople/client.rb, line 66
def request(method, path, data, json = true)
  http = configuration.http
  data = configuration.data.merge(data)

  case method
  when "GET"
    get(http, path, data, json)
  when "POST"
    post(http, path, data, json)
  end
end
send_message_to_buddy(buddy_id, content, attach = nil) click to toggle source
# File lib/mypeople/client.rb, line 100
def send_message_to_buddy(buddy_id, content, attach = nil) 
  method = APIS[:send_message_to_buddy][:method]
  path = APIS[:send_message_to_buddy][:path]
  data = if content.empty?
           {
             "buddyId" => buddy_id,
             "attach" => attach
           }
         else
           {
             "buddyId" => buddy_id,
             "content" => content
           }
         end

  request(method, path, data)
end
send_message_to_group(group_id, content, attach = nil) click to toggle source
# File lib/mypeople/client.rb, line 138
def send_message_to_group(group_id, content, attach = nil) 
  method = APIS[:send_message_to_group][:method]
  path = APIS[:send_message_to_group][:path]
  data = {
    "groupId" => group_id,
    "content" => content
  }

  request(method, path, data)
end