Class: E621::API Private
- Inherits:
-
Object
- Object
- E621::API
- Defined in:
- lib/rubyhexagon/helper/api.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An interface class, to unify calls from other code to e621 [dot] net. This class handles rate limiting, as well as provides a more uniform approach in making requests. It also ensures that a proper user agent is sent, as required by the e621 API.
Instance Attribute Summary collapse
-
#user_agent ⇒ Hash
readonly
private
User agent, used to identify this gem against e621.
Instance Method Summary collapse
-
#fetch(noun, action, query) ⇒ Hash
private
Fetches information from e621 and returns data to caller.
-
#initialize(rspec = false) ⇒ Object
constructor
private
Initializer for API.
Constructor Details
#initialize(rspec = false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializer for API. All methods are instance methods.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rubyhexagon/helper/api.rb', line 39 def initialize(rspec = false) @user_agent = { 'User-Agent' => "#{E621::NAME}/#{E621::VERSION} (by maxine_red on e621" } @rspec = rspec @base = if @rspec || !defined? RSpec then 'https://e621.net' else 'spec/data' end lock_path = '/tmp/rubyhexagon.lock' @lock_file = File.open(lock_path, 'a') end |
Instance Attribute Details
#user_agent ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
User agent, used to identify this gem against e621.
32 33 34 |
# File 'lib/rubyhexagon/helper/api.rb', line 32 def user_agent @user_agent end |
Instance Method Details
#fetch(noun, action, query) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetches information from e621 and returns data to caller. This also takes into account rate limiting.
61 62 63 64 65 66 |
# File 'lib/rubyhexagon/helper/api.rb', line 61 def fetch(noun, action, query) query = query.to_a.map { |q| "#{q.first}=#{q.last}" }.join('&') query = "?#{query}" unless query == '' uri = "#{@base}/#{noun}/#{action}.json#{query}" fetch_data(uri) end |