Skip to content

Commit

Permalink
Added create_link method which simplifies creating _links for API cal…
Browse files Browse the repository at this point in the history
…lbacks
  • Loading branch information
colinc committed Jan 13, 2014
1 parent 6b9434d commit dcca1d5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/desk/client.rb
Expand Up @@ -82,6 +82,21 @@ def plural(singular)
end
end

def create_link(type, class_or_hash, id = nil, sub_class = nil, sub_id = nil)
if class_or_hash.class == Hashie::Deash
{type.to_sym => {
:class => class_or_hash._links.self['class'],
:href => class_or_hash._links.self['href']
}}
elsif class_or_hash.class == String
href = Desk.api_path+plural(class_or_hash)+"/#{id}"
href += "/"+plural(sub_class)+"/#{sub_id}" if sub_class != nil
{type.to_sym => { :class => class_or_hash, :href => href }}
else
nil
end
end

private

def setup_functions(base, endpoints_list)
Expand Down

0 comments on commit dcca1d5

Please sign in to comment.