README.md in bungie_client-0.6.0 vs README.md in bungie_client-1.0.0

- old
+ new

@@ -17,156 +17,99 @@ $ gem install bungie_client ## Usage -For public requests you must initialize a client of api with `BungieClient::Client`. +This gem contains two main classes: **BungieClient::Client**, **BungieClient::Wrappers::Default** and his inherits. -~~~~ruby -client = BungieClient::Client.new :api_key => '1234' -~~~~ - -The option `api_key` only necessary for this class and API. For getting API key, please visit the [bungie page](https://www.bungie.net/en/user/api). - -After it you can send your request to [Bungie Endpoint](http://destinydevs.github.io/BungieNetPlatform/docs/Endpoints). - -The full information about classes and modules and their methods you can find in yard-comments and [rubydoc](http://www.rubydoc.info/gems/bungie_client). - -### BungieClient::Auth - -This module has two methods: authentication in bungie.net by PSN or Xbox Live and checking this authentication with cookies that was returned early. - -**Example:** - -~~~~ ruby -# Authenticate and get bungie cookies -jar = BungieClient::Auth.auth 'example@mail.com', 'example', 'psn' - -# Check authentication -p BungieClient::Auth.auth_possible? (jar || []) -~~~~ - -### BungieClient::Cache - -It's class created for easy wrapping another cache clients, e.g. [Redis](https://github.com/redis/redis-rb). - -**Examples of initialization:** - -~~~~ruby -require 'redis' - -BungieClient::Cache.new( - :ttl => 900, - :client => Redis.new, - :get => Proc.new { |c, key| c.get key }, - :set => Proc.new { |c, key, value, ttl| c.setex key, ttl, value } -) -~~~~ - -**For Rails wrapper:** - -~~~~ruby -BungieClient::Cache.new( - :ttl => @ttl, - :client => Rails.cache, - :get => Proc.new { |c, key| c.read key }, - :set => Proc.new { |c, key, value, ttl| c.write key, value, expires_in: ttl } -) -~~~~ - ### BungieClient::Client -It's main class that makes possible to send any requests to Bungie and connects cache wrapper and auth module in one client. +It's main class that makes possible to send any requests to Bungie and connects auth module in one client. It needs for public/private requests to Bungie API. **For this you should initialize your client for the next example:** ~~~~ruby -client = BungieClient::Client.new( +@client = BungieClient::Client.new( :api_key => 'YOUR_API_KEY', - :authentication => true, :username => 'test@test.test', :password => '1234', - :type => 'psn', - :cache => BungieClient::Cache.new( - :ttl => 900, - :client => Redis.new, - :get => Proc.new { |c, key| c.get key }, - :set => Proc.new { |c, key, value, ttl| c.setex key, ttl, value } - ) + :type => 'psn' ) ~~~~ +**or simply:** + +~~~~ruby +@client = BungieClient::Client.new :api_key => 'YOUR_API_KEY' +~~~~ + +* The option `api_key` only necessary for this class and API. For getting API key, please visit the [bungie page](https://www.bungie.net/en/user/api). +* After it you can send your request to [Bungie Endpoint](http://destinydevs.github.io/BungieNetPlatform/docs/Endpoints). +* The full information about classes and modules and their methods you can find in yard-comments and [rubydoc](http://www.rubydoc.info/gems/bungie_client). + #### How it initialized: -* Before working the client tries to authenticate in bungie, if you pass `authentication` option with account data, and after it uses cookies for next requests. -* If store your cookies in any place you can define they with `cookies` option without `authentication`. -* For requests optimization you should use caching of your requests defined `BungieClient::Cache` in `cache` option. +* Before working the client tries to authenticate in bungie, if you pass `username` and `password` option with account data, and after it uses cookies for next requests. +* If you want to store your cookies in any place you can define they with `cookies` option without authentication. * After this operations your client is done for usage. -> The authentication and caching are optional for client, it requires only `api_key` in your hash. +> The authentication optional for client, it requires only `api_key` in your hash for initializer. #### Sending requests **Now you can send requests, e.g. for finding user information and getting his profile:** ~~~~ruby -# search account -s = client.get_response "Destiny/SearchDestinyPlayer/2/RuBAN-GT" +@client.get_response "Destiny/SearchDestinyPlayer/2/RuBAN-GT" +~~~~ -p s = s.first if !s.nil? && s.length == 1 +#### Note -# get profile with characters -p client.get_response "Destiny/#{s['membershipType']}/Account/#{s['membershipId']}" unless s.nil? -~~~~ +* For requests optimization you should use any caching of your requests. -## One sample of Rails integration +### BungieClient::Auth -If you want to work with Rails you can create easy wrapper, such as: +This module has two methods: authentication in bungie.net by *PSN* or *Xbox Live* and checking this authentication with cookies that was returned early. +**Example:** + ~~~~ ruby -require 'bungie_client' +# Authenticate and get bungie cookies +jar = BungieClient::Auth.auth 'example@mail.com', 'example', 'psn' -class RailsBungieWrapper - class << self - def api_key=(value) - @api_key = value - end - def ttl=(value) - @ttl = value - end +# Check authentication +p BungieClient::Auth.auth_possible? (jar || []) +~~~~ - def init - yield(self) if block_given? - end +### BungieClient::Wrappers::Default - def client - return @client unless @client.nil? +If you don't like long code as for me you should use **Wrappers**. It's classes can call api services with dynamically generated methods with snake case like name services. Also it can change url parameters to needed values and in inherits of this class it can be do automatically. - @client = BungieClient::Client.new( - :api_key => @api_key, - :cache => BungieClient::Cache.new( - :ttl => @ttl, - :client => Rails.cache, - :get => Proc.new { |c, key| c.read key }, - :set => Proc.new { |c, key, value, ttl| c.write key, value, expires_in: ttl } - ) - ) - end - end -end +The initialization of **Wrappers::Default** is similar to **Client**: all arguments of initializer will be passed to **Client** which is class variable of wrapper. + +~~~~ruby +@wrapper = BungieClient::Wrappers::Default.new :api_key => 'YOUR_API_KEY' ~~~~ -After it, you should add your initializer to `config\initializers`: +Now you can sending your requests with beautiful and effective code: ~~~~ruby -RailsBungieWrapper.init do |config| - config.api_key = '1234' -end +@wrapper.search_destiny_player :membershipType => '2', :displayName => 'RuBAN-GT' ~~~~ -In next operations the `RailsBungieWrapper.client` will be available for calls. +If you need **more** you can define your own wrappers such as **Wrappers::User**: +~~~~ruby +@user = BungieClient::Wrappers::User.new( + :api_key => 'YOUR_API_KEY', + :display_name => 'RuBAN-GT', + :membership_type => '2' +) + +@user.search_destiny_player +~~~~ + ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/RuBAN-GT/bungie_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License @@ -174,5 +117,9 @@ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). ## Fireteam If you want to fight with Oryx with me or create any interesting applications for Destiny, you can add me ([https://www.bungie.net/en/Profile/254/12488384](https://www.bungie.net/en/Profile/254/12488384)). + +## Note + +* In the source code you can fine `services_parser.rb`. It's script created for getting full list of Bungie API services, for result it generates `services.yml` in lib. \ No newline at end of file