Class: PostingClient

Inherits:
Client show all
Defined in:
lib/client/posting_client.rb

Overview

The PostingClient class allows clients to use 3taps Posting API to store and retrieve postings in the 3taps system.

Its methods are used to query API with appropriate requests:

client = PostingClient.new
client.get_posting(post_key)      # => returns a single Posting object
client.create_posting(postings)   # => returns array of CreateResponse objects
client.update_posting(postings)   # => returns array of UpdateResponse objects
client.delete_posting(post_keys)  # => returns array of DeleteResponse objects
client.exists_posting(posting)    # => returns array of ExistsResponse objects

Constant Summary

Constants inherited from Client

Client::DEFAULT_API_PORT, Client::DEFAULT_URL, Client::TIMEOUT

Instance Method Summary collapse

Methods inherited from Client

#execute_get, #execute_post, #initialize

Constructor Details

This class inherits a constructor from Client

Instance Method Details

#create_posting(postings) ⇒ Object

Method create_posting saves a single new posting and multiple new postings in 3taps.

Examples

client = PostingClient.new
client.update_posting([posting1, posting2])  #=> Array of CreateResponse objects

client = PostingClient.new
client.update_posting(posting2)  #=> Array with single CreateResponse object


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/client/posting_client.rb', line 33

def create_posting(postings)
  postings = [postings] unless postings.is_a? Array
  data = "["
  data << postings.collect{|posting| posting.to_json}.join(',')
  data << "]"
  params = "postings=#{data}"
  p params
  response = execute_post("/posting/create", params)
  p response.inspect
  p decode(response)
  CreateResponse.from_array(decode(response))
end

#delete_posting(post_keys) ⇒ Object

Method delete_posting deletes a single posting and multiple postings from 3taps.

Examples:

client = PostingClient.new
response = client.delete_posting(...Array of postKeys strings...)     # => Array of DeleteResponse objects

client = PostingClient.new
key = some_posting.postKey
response = client.delete_posting(key)     # => Array with single DeleteResponse object


75
76
77
78
79
80
# File 'lib/client/posting_client.rb', line 75

def delete_posting(post_keys)
  post_keys = [post_keys] unless post_keys.is_a? Array
  params = "data=['#{post_keys.join("','")}']"
  response = execute_post("posting/delete", params)
  DeleteResponse.from_hash(decode(response))
end

#exists_posting(posting) ⇒ Object

NOT USED

Returns information on the existence of postings.


86
87
88
89
90
91
# File 'lib/client/posting_client.rb', line 86

def exists_posting(posting)
  params = "ids=[#{posting.to_json_for_status}]"
  response = execute_post("/posting/exists", params)
  p decode(response)[0]
  ExistsResponse.new(decode(response)[0])
end

#get_posting(post_key) ⇒ Object

Retrieves an information about a single posting.

Example

client = PostingClient.new
client.get_posting("...postKey string...") => Posting object


19
20
21
22
# File 'lib/client/posting_client.rb', line 19

def get_posting(post_key)
  response = execute_get("/posting/get/" + post_key)
  Posting.new(decode(response))
end

#update_posting(postings) ⇒ Object

Method update_posting updates a single posting and multiple postings on 3taps.

Examples:

client = PostingClient.new
client.update_posting([posting1, posting2])  #=> Array of UpdateResponse objects

client = PostingClient.new
client.update_posting(posting)  #=> Array with single UpdateResponse object


55
56
57
58
59
60
61
62
63
# File 'lib/client/posting_client.rb', line 55

def update_posting(postings)
  postings = [postings] unless postings.is_a? Array
  data = "["
  data << postings.collect{|posting| posting.to_json_for_update}.join(',')
  data << "]"
  params = "data=#{data}"
  response = execute_post("posting/update", params)
  UpdateResponse.from_hash(decode(response))
end