This gem wraps over the Fyber Offer Wall API and provides you with a simple way to query the offers from your Ruby app.
The FyberApiWrapper will hide all the gritty details like compression, request signing and server response signature checks from you, so you can just concentrate on querying the API.
For now, although you can set some other format, only JSON will be parsed correctly.
Add this line to your application's Gemfile:
gem 'fyber_api_wrapper'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fyber_api_wrapper
FyberApiWrapper has been tested against MRI 2.0, 2.1.1, and 1.9.3 . Other versions should work but use them at your own risk.
The Fyber API requires a few parameters to be set, namely:
- appid
- format
- device_id
- locale
- ip
- offer_types
- api_key
In your app, configure the FyberApiWrapper and supply those parameters:
require 'fyber_api_wrapper'
FyberApiWrapper.configure do |config|
config.format = :json
config.appid = 123
config.device_id = '"your device ID"' # MIND THE QUOTES. device ID has quotes.
config.ip = "1.2.3.4"
config.offer_types = [112]
config.api_key = "your-api-key"
end
NOTE: Since the api_key is confidential, treat it accordingly. For example, use environment variables, do not put it on github for everyone to see.
Having configured the gem, you can make requests and obtain offers:
require 'fyber_api_wrapper'
# assuming you've configured the gem
params = { :uid => "luc", :pub0 => "campaign1", :page => "1" }
# use the shortcut.
# you could also do:
# Request::Offer.new(params).get
offers = FyberApiWrapper.get_offers(params)
# get the offer info
puts offers.count # 30
puts offers.code # "OK"
# meta inf
puts offers.information.app_name # "Demo iframe for publisher - do not touch"
puts offers.information.virtual_currency # "Coins"
#offers
offer = offers[0] # FyberApiWrapper::Response::Offer
puts offer.title # "Connect - Social Map & Address Book"
puts offer.link # "http://api.sponsorpay.com/bd744b22cc10f7a3b13d5d661cbd9ba5/fb707b4efdaa5b5f/mobile/DE/157/offers/275789"
# offer types for this offer
puts offer.offer_types.first.offer_type_id # 101
puts offer.offer_types.first.readable # "Download"
# time to payout for this offer
puts offer.time_to_payout.amount # 3300
puts offer.time_to_payout.readable # "1 hour"
# thumbnails
puts offer.thumbnail.lowres # "http://cdn1.sponsorpay.com/app_icons/20264/small_mobile_icon.png"
puts offer.thumbnail.hires # "http://cdn1.sponsorpay.com/app_icons/20264/big_mobile_icon.png"
# iterate over the offer items provided by the offers collection
offers.each do |offer|
puts offer.title
end
The FyberAPIWrapper will raise exceptions in the following cases:
- a 401 Unauthorized response will cause the FyberApiWrapper::NotAuthorizedError to be raised. The most likely cause of that is forgetting to configure the api_key ;
- a 400 Bad Request response will cause the FyberApiWrapper::BadRequestError to be raised. This occurs if you forget to specify parameters such as appid and device_id, or simply requesting a page that does not exist;
- all the other HTTP error code will trigger the FyberApiWrapper::HTTPError exception.
Q: I did everything as described and I'm getting "NoMethodError: undefined method `appid' for nil:NilClass" when trying to execute FyberApiWrapper.get_offers(params)
A: You must have forgotten to configure the FyberApiWrapper. See Configuration above
- Fork it ( https://github.com/yurivm/fyber_api_wrapper/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request