Class: BungieSdk::Client
Overview
Base class for the BungieSdk. All workflows should start with a `Client`.
This class currently expects the user to authenticate with OAuth in order to access private API endpoints. This will be changed in the future to allow users to not provide an authentication token if they only wish to access public Bungie API endpoints. Bungie Applications can be created [here](www.bungie.net/en/Application).
The authentication workflow for this SDK allows for a couple of different options. First, if you already have a valid `OAuth2::AccessToken` for your Bungie Application, you can provide that to the `token` parameter on creation of this class and this application will handle refreshing the token when need be. If you do not already have an access token, you can provide your Bungie Application's client id and client secret to their respective arguments in this class's constructor and this application will handle authentication with those credentials. Optionally, if you would like to save your access token to your local filesystem, provide a path for that file in the `token_filepath` parameter. If a filepath is provided in `token_filepath` but no access token is supplied through `token`, then this application will attempt to read that token from file and use it for authentication. This is recommended as it will reduce the number of times you need to authenticate this app in your web browser. If `token_filepath` is supplied, `token` is not, and there is no existing token stored in the file at `token_filepath`, then this application will require the user to authenticate through their web browser and then save that information to file.
Constant Summary
Constants inherited from ApiAgent
Instance Attribute Summary
Attributes inherited from ApiAgent
Instance Method Summary collapse
- #destiny_memberships ⇒ Object
-
#initialize(token: nil, token_filepath: nil, api_key: ENV['BUNGIE_API_KEY'], client_id: ENV['BUNGIE_CLIENT_ID'], client_secret: ENV['BUNGIE_CLIENT_SECRET'], redirect_uri: ENV['BUNGIE_REDIRECT_URI'] || 'http://localhost:8080/oauth/callback') ⇒ Client
constructor
A new instance of Client.
- #memberships ⇒ Object
Methods inherited from ApiAgent
#delete, #get, #post, #put, #request, #run
Constructor Details
#initialize(token: nil, token_filepath: nil, api_key: ENV['BUNGIE_API_KEY'], client_id: ENV['BUNGIE_CLIENT_ID'], client_secret: ENV['BUNGIE_CLIENT_SECRET'], redirect_uri: ENV['BUNGIE_REDIRECT_URI'] || 'http://localhost:8080/oauth/callback') ⇒ Client
Returns a new instance of Client.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bungie_sdk/client.rb', line 43 def initialize(token: nil, token_filepath: nil, api_key: ENV['BUNGIE_API_KEY'], client_id: ENV['BUNGIE_CLIENT_ID'], client_secret: ENV['BUNGIE_CLIENT_SECRET'], redirect_uri: ENV['BUNGIE_REDIRECT_URI'] || 'http://localhost:8080/oauth/callback') super(nil) unless TokenManager.instance.initialized? TokenManager.instance.setup_token(token, token_filepath, api_key, client_id, client_secret, redirect_uri) end end |
Instance Method Details
#destiny_memberships ⇒ Object
68 69 70 |
# File 'lib/bungie_sdk/client.rb', line 68 def destiny_memberships memberships['destinyMemberships'].map {|data| Destiny2::Membership.new(data) } end |
#memberships ⇒ Object
62 63 64 |
# File 'lib/bungie_sdk/client.rb', line 62 def memberships @memberships ||= run(get('/Platform/User/GetMembershipsForCurrentUser')).body end |