Module: Freelancer::API::Employer::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#choose_winner_for_project(*args) ⇒ Object

Choose one or more winners for a project

Valid parameters are:

- project_id: the id of the project to choose a winner for
- user_id: a single user id, or an array of user ids, to be made winners of the project


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/freelancer/api/employer.rb', line 149

def choose_winner_for_project(*args)

  params = extract_params(args)

  # Handle the user id attribute, make sure it's an array and not set to nil to
  # simplify the handling below.
  params[:user_id] ||= []
  params[:user_id] = [ params[:user_id] ] unless params[:user_id].is_a?(Array)

  # Execute the service call
  result = api_get("/Employer/chooseWinnerForProject.json", build_api_params({
    :projectid => params[:project_id],
    :useridcsv => params[:user_id].join(",")
  }))

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

#delete_draft_project(*args) ⇒ Object

Delete a draft project

Valid parameters are:

- project_id: the id of the project to delete


130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/freelancer/api/employer.rb', line 130

def delete_draft_project(*args)

  params = extract_params(args)

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

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

#eligible_for_trial_projectObject

Check if the current user is eligible to post trial projects



39
40
41
42
43
44
# File 'lib/freelancer/api/employer.rb', line 39

def eligible_for_trial_project
  
  result = api_get("/Employer/eligibleForTrialProject.json")
  ::Freelancer::Models::Eligibility.parse(result, :shift => :"json-result")

end

#eligible_for_trial_project?Boolean

Returns true if the current user is eligible to post trial projects, false otherwise

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/freelancer/api/employer.rb', line 48

def eligible_for_trial_project?
  eligibility = eligible_for_trial_project
  !eligibility.nil? && eligibility.eligible?
end

#invite_user_to_project(*args) ⇒ Object

Invite one or more users to bid on a project

Valid parameters are:

- project_id: the id of the project to invite users to
- user_id: a single user id, or an array of user ids, to invite to the project
- username: a single username, or an array of usernames, to invite to the project


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/freelancer/api/employer.rb', line 175

def invite_user_to_project(*args)

  params = extract_params(args)

  # Handle the username and user id attributes, make sure they're an array and not
  # set to nil to simplify the handling below.
  params[:user_id] ||= []
  params[:user_id] = [ params[:user_id] ] unless params[:user_id].is_a?(Array)
  params[:username] ||= []
  params[:username] = [ params[:username] ] unless params[:username].is_a?(Array)

  # Execute the service call
  result = api_get("/Employer/inviteUserForProject.json", build_api_params({
    :projectid => params[:project_id],
    :useridcsv => params[:user_id].join(","),
    :usernamecsv => params[:username].join(",")
  }))

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

end

#new_project(project) ⇒ Object

Post a new project



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/freelancer/api/employer.rb', line 54

def new_project(project)

  params = new_project_params(project)

  # Execute the service call
  result = api_get("/Employer/postNewProject.json", params)

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

end

#new_project_draft(project) ⇒ Object

Post a new project draft



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/freelancer/api/employer.rb', line 67

def new_project_draft(project)

  params = new_project_params(project)

  # Execute the service call
  result = api_get("/Employer/postNewDraftProject.json", params)

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

end

#new_trial_project(project) ⇒ Object

Post a new trial project



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/freelancer/api/employer.rb', line 80

def new_trial_project(project)

  params = new_project_params(project)

  # Execute the service call
  result = api_get("/Employer/postNewTrialProject.json", params)

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

end

#posted_projects(*args) ⇒ Object

Retrieve a list of projects posted by a user. By default, this retrieves the projects posted by the currently authenticated user.

Valid parameters are:

- status: the status value to filter projects by (defaults to 2 (open and frozen))
- user_id: the id of the user to list projects for (defaults to current user)
- project_id: the project id to filter projects by
- type: the project type to use ('active', 'trial' and 'draft' - defaults to 'active')
- count: the number of results to return (defaults to 50)
- page: the page to retrieve (defaults to 0)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/freelancer/api/employer.rb', line 16

def posted_projects(*args)

  params = extract_params(args)

  # Use a blank type value if type is set to 'active'
  params[:type] = nil if params[:type] == "active"

  # Execute the service call
  result = api_get("/Employer/getPostedProjectList.json", build_api_params({
    :status => params[:status],
    :userid => params[:user_id],
    :projectid => params[:project_id],
    :projectoption => params[:type],
    :count => params[:count],
    :page => params[:page]
  }))

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

#update_project(project) ⇒ Object

Update a project



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

def update_project(project)

  params = {}
  params[:projectid] = project.id
  params[:projectdesc] = project.short_description
  params[:jobtypecsv] = project.jobs.join(",")

  # Execute the service call
  result = api_get("/Employer/updateProjectDetails.json", params)

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

end

#upgrade_trial_project(*args) ⇒ Object

Upgrade a trial project to a normal project

Valid parameters are:

- project_id: the id of the project to ugprade


112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/freelancer/api/employer.rb', line 112

def upgrade_trial_project(*args)

  params = extract_params(args)

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

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

end