Class: FlurryHarvest::Client
- Inherits:
-
Object
- Object
- FlurryHarvest::Client
- Defined in:
- lib/flurry_harvest/client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
custom agent string.
-
#api_access_code ⇒ Object
readonly
Returns the value of attribute api_access_code.
-
#api_host ⇒ Object
readonly
api.flurry.com.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_port ⇒ Object
readonly
80 || 443.
-
#api_url ⇒ Object
readonly
appCircle/v2/getRecommendations.
-
#debug_mode ⇒ Object
readonly
Returns the value of attribute debug_mode.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
Instance Method Summary collapse
-
#encode_mac(mac_address) ⇒ Object
SHA1 encode of mac address D9:2A:1A:0C:FD:0B should become CF41A96B9A6E4FE2942B4A51F350D7FD722E38B2.
-
#fetch_offers(options = {}) ⇒ Object
mandatory params iosUdid - :udid sha1Mac - :mac platform - :platform (IPHONE, IPAD, AND) ipAddress - :ip.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #log(message) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/flurry_harvest/client.rb', line 12 def initialize( = {}) @api_access_code = [:api_access_code] || (raise FlurryHarvest::ApiAccessCodeNotSet) @api_key = [:api_key] || (raise FlurryHarvest::ApiKeyNotSet) @api_host = [:api_host] || 'api.flurry.com' @api_url = [:api_url] || '/appCircle/v2/getRecommendations' @api_port = [:api_port] || 80 @agent = [:agent] @debug_mode = [:debug_mode] || false log "Initialize:" log "-----------" log "api_access_code: #{api_access_code}" log "api_key: #{api_key}" log "api_host: #{api_host}" log "api_url: #{api_url}" log "api_port: #{api_port}" log "agent: #{agent}" log "full options: #{}" end |
Instance Attribute Details
#agent ⇒ Object (readonly)
custom agent string
9 10 11 |
# File 'lib/flurry_harvest/client.rb', line 9 def agent @agent end |
#api_access_code ⇒ Object (readonly)
Returns the value of attribute api_access_code.
2 3 4 |
# File 'lib/flurry_harvest/client.rb', line 2 def api_access_code @api_access_code end |
#api_host ⇒ Object (readonly)
api.flurry.com
4 5 6 |
# File 'lib/flurry_harvest/client.rb', line 4 def api_host @api_host end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/flurry_harvest/client.rb', line 3 def api_key @api_key end |
#api_port ⇒ Object (readonly)
80 || 443
6 7 8 |
# File 'lib/flurry_harvest/client.rb', line 6 def api_port @api_port end |
#api_url ⇒ Object (readonly)
appCircle/v2/getRecommendations
5 6 7 |
# File 'lib/flurry_harvest/client.rb', line 5 def api_url @api_url end |
#debug_mode ⇒ Object (readonly)
Returns the value of attribute debug_mode.
10 11 12 |
# File 'lib/flurry_harvest/client.rb', line 10 def debug_mode @debug_mode end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
8 9 10 |
# File 'lib/flurry_harvest/client.rb', line 8 def query @query end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
7 8 9 |
# File 'lib/flurry_harvest/client.rb', line 7 def raw_data @raw_data end |
Instance Method Details
#encode_mac(mac_address) ⇒ Object
SHA1 encode of mac address D9:2A:1A:0C:FD:0B should become CF41A96B9A6E4FE2942B4A51F350D7FD722E38B2
81 82 83 |
# File 'lib/flurry_harvest/client.rb', line 81 def encode_mac(mac_address) Digest::SHA1.hexdigest(mac_address).upcase end |
#fetch_offers(options = {}) ⇒ Object
mandatory params iosUdid - :udid sha1Mac - :mac platform - :platform (IPHONE, IPAD, AND) ipAddress - :ip
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/flurry_harvest/client.rb', line 37 def fetch_offers( = {}) log "fetch_offers.options: #{}" raise Exception, "UDID is Required" if !.has_key?(:udid) raise Exception, "IP is Required" if !.has_key?(:ip) = { :apiAccessCode => @api_access_code, :apiKey => @api_key, :iosUdid => [:udid], :sha1Mac => [:mac] ? encode_mac([:mac]) : nil, :platform => ([:platform] || 'IPHONE').upcase, :ipAddress => [:ip] } @query = to_query() http = Net::HTTP.new(@api_host, @api_port) http.use_ssl = (@api_port.to_i == 443) http.verify_mode = OpenSSL::SSL::VERIFY_NONE path = "#{@api_url}?#{@query}" log "Request: http://#{api_host}:#{api_port}#{path}" response = http.get(path, headers) log "Response.body: #{response.body}" @raw_data = JSON.parse(response.body) log "Response.raw_data: #{@raw_data}" if response.code.to_i == 200 result = decode log "Result: #{result.inspect}" return result unless @raw_data.empty? else raise FlurryHarvest::ApiError, message: "#{@raw_data['code']} - #{@raw_data['message']}" end false end |
#log(message) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/flurry_harvest/client.rb', line 85 def log() return unless debug_mode = "FlurryHarvest [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]: #{}" if defined? ::Rails ::Rails.logger.info else Kernel.puts end end |