Module: Freelancer::API::Message::InstanceMethods

Defined in:
lib/freelancer/api/message.rb

Instance Method Summary collapse

Instance Method Details

#mark_message_as_read(*args) ⇒ Object

Mark a message as read

Valid parameters are:

- message_id: the id of the message to mark as read


114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/freelancer/api/message.rb', line 114

def mark_message_as_read(*args)

  params = extract_params(args)

  # Execute the service call
  result = api_get("/Message/markMessageAsRead.json", build_api_params({
    :id => params[:message_id]
  }))

  # Parse and return the response
  ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")

end

#message_thread(*args) ⇒ Object

Retrieve the full thread of private messages sent between two users within a project.

Valid parameters are:

- project_id: the id of the project to load messages for
- between_user_id: the id of the receiving user to load the thread for
- count: the number of messages to retrieve (defaults to 50)
- page: the page number to retrieve (defaults to 0)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/freelancer/api/message.rb', line 69

def message_thread(*args)

  params = extract_params(args)

  # Execute the service call
  result = api_get("/Message/loadMessageThread.json", build_api_params({
    :projectid => params[:project_id],
    :betweenuserid => params[:between_user_id],
    :count => params[:count],
    :page => params[:page]
  }))

  # Parse and return the response
  ::Freelancer::Models::Message.parse_collection(result, :shift => [ :"json-result", :items, :message ])
  
end

#messages(*args) ⇒ Object

Return the private messages sent to the current user

Valid parameters are:

- project_id: the project id to filter messages by
- count: the number of results to return (defaults to 50)
- page: the page to retrieve (defaults to 0)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/freelancer/api/message.rb', line 12

def messages(*args)

  params = extract_params(args)

  # Execute the service call
  result = api_get("/Message/getInboxMessages.json", build_api_params({
    :projectid => params[:project_id],
    :count => params[:count],
    :page => params[:page]
  }))

  # Parse and return the response
  ::Freelancer::Models::Message.parse_collection(result, :shift => [ :"json-result", :items ])

end

#send_message(*args) ⇒ Object

Send a private message to another user

Valid parameters are:

- project_id: the id of the project to send message for
- text: the text of the message to send
- user_id: the id of the user to send the message to
- username: the username of the user to send the message to


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/freelancer/api/message.rb', line 93

def send_message(*args)

  params = extract_params(args)

  # Execute the service call
  result = api_get("/Message/sendMessage.json", build_api_params({
    :projectid => params[:project_id],
    :messagetext => params[:text],
    :userid => params[:user_id],
    :username => params[:username]
  }))

  # Parse and return the response
  ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
  
end

#sent_messages(*args) ⇒ Object

Retrieve the messages the current user has sent to other users

Valid parameters are:

- count: the number of results to return (defaults to 50)
- page: the page to retrieve (defaults to 0)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/freelancer/api/message.rb', line 33

def sent_messages(*args)

  params = extract_params(args)

  # Execute the service call
  result = api_get("/Message/getSentMessages.json", build_api_params({
    :count => params[:count],
    :page => params[:page]
  }))

  # Parse and return the response
  ::Freelancer::Models::Message.parse_collection(result, :shift => [ :"json-result", :items ])

end

#unread_message_countObject

Retrieve the number of unread messages the current user has available



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/freelancer/api/message.rb', line 49

def unread_message_count

  result = api_get("/Message/getUnreadCount.json")
  json = JSONMapper::Parser.parse(result)

  if !json.nil? && json.key?(:"json-result")
    return json[:"json-result"][:unreadcount].to_i
  end
  return nil

end