Class: PickFlair
- Inherits:
-
Object
- Object
- PickFlair
- Includes:
- HTTParty
- Defined in:
- lib/awardflair/pickflair_api.rb
Instance Attribute Summary collapse
-
#badges ⇒ Object
Returns the value of attribute badges.
Instance Method Summary collapse
- #award_badge(badge_identifier) ⇒ Object
- #award_badge_by_email(badge_identifier, email_of_recipient, options = {}) ⇒ Object
- #collect_badges ⇒ Object
- #find_badges(search_terms) ⇒ Object
- #get_badge_by_identifier(badge_identifier) ⇒ Object
-
#initialize(api_key, api_secret, application_id) ⇒ PickFlair
constructor
A new instance of PickFlair.
Constructor Details
#initialize(api_key, api_secret, application_id) ⇒ PickFlair
Returns a new instance of PickFlair.
37 38 39 40 41 42 |
# File 'lib/awardflair/pickflair_api.rb', line 37 def initialize(api_key, api_secret, application_id) @badges ||= [] self.class.base_uri 'https://www.pickflair.com/api/v1' self.class.default_params :output => 'json'; self.class.format :json @auth = {:api_key => api_key, :api_secret => api_secret, :application_id => application_id} end |
Instance Attribute Details
#badges ⇒ Object
Returns the value of attribute badges.
35 36 37 |
# File 'lib/awardflair/pickflair_api.rb', line 35 def badges @badges end |
Instance Method Details
#award_badge(badge_identifier) ⇒ Object
64 65 66 67 |
# File 'lib/awardflair/pickflair_api.rb', line 64 def award_badge(badge_identifier) api_response = self.class.post("/badge_request_logs.json", :body => token.merge(:badge_id => badge_identifier)) api_response.parsed_response["data"]["badge_awarding_url"] end |
#award_badge_by_email(badge_identifier, email_of_recipient, options = {}) ⇒ Object
69 70 71 72 |
# File 'lib/awardflair/pickflair_api.rb', line 69 def award_badge_by_email(badge_identifier, email_of_recipient, ={}) api_response = self.class.post("/email_awards.json", :body => token.merge(:badge_id => badge_identifier, :email => email_of_recipient).merge()) api_response.parsed_response["data"]["badge_award_url"] end |
#collect_badges ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/awardflair/pickflair_api.rb', line 44 def collect_badges @badges = [] array_of_badges_from_api.each do |badge_hash| @badges << PFBadge.new(badge_hash.merge(:pickflair_instance => self)) end @badges end |
#find_badges(search_terms) ⇒ Object
60 61 62 |
# File 'lib/awardflair/pickflair_api.rb', line 60 def find_badges(search_terms) badges.select {|badge| badge.qualify?(search_terms)} end |
#get_badge_by_identifier(badge_identifier) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/awardflair/pickflair_api.rb', line 74 def get_badge_by_identifier(badge_identifier) badges_that_match = find_badges(:id => badge_identifier) if badges_that_match.any? badges_that_match.first else api_response = self.class.get("/badges/#{badge_identifier}.json", :body => token) api_response.parsed_response["data"] end end |