Class: Weasyl::API
Overview
Helper class to abstract actual API communication
Instance Attribute Summary collapse
-
#key ⇒ String
Sets the API key.
Instance Method Summary collapse
- #fetch(endpoint, params = {}) ⇒ Object
-
#version ⇒ String
Display version of weasyl API we connected to.
-
#whoami ⇒ Hash
A test method to test API connection.
Instance Attribute Details
#key ⇒ String
Sets the API key. OAuth isn’t supported yet.
30 31 32 |
# File 'lib/weasyl/api.rb', line 30 def key @key end |
Instance Method Details
#fetch(endpoint, params = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/weasyl/api.rb', line 31 def fetch(endpoint, params = {}) params = if params.empty? '' else "?#{params.to_a.map { |a| a.join('=') }.join('&')}" end raise ArgumentError, 'API key can\'t be empty' if @key.nil? JSON.parse(URI.parse("https://weasyl.com/api/#{endpoint}#{params}") .read('X-Weasyl-API-Key' => @key, 'User-Agent' => Weasyl::USER_AGENT), symbolize_names: true) end |
#version ⇒ String
Display version of weasyl API we connected to
55 56 57 |
# File 'lib/weasyl/api.rb', line 55 def version fetch(:version)[:short_sha] end |
#whoami ⇒ Hash
A test method to test API connection
47 48 49 |
# File 'lib/weasyl/api.rb', line 47 def whoami fetch(:whoami) end |