class PostingClient
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
Public Instance Methods
create_posting(postings)
click to toggle source
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
# 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)
click to toggle source
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
# 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)
click to toggle source
NOT USED
Returns information on the existence of postings.
# 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)
click to toggle source
Retrieves an information about a single posting.
Example
client = PostingClient.new client.get_posting("...postKey string...") => Posting object
# 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)
click to toggle source
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
# 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