Module: Jimgur
- Defined in:
- lib/jimgur.rb,
lib/jimgur/version.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
'0.1.1'
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/jimgur.rb', line 5 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
8 9 10 11 |
# File 'lib/jimgur.rb', line 8 def self.configure self.configuration ||= Configuration.new yield(configuration) end |
.upload(image) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jimgur.rb', line 21 def self.upload image api_uri = URI.parse("https://api.imgur.com") api_public_key = "Client-ID #{self.configuration.client_id}" endpoints = { image: "3/image", } img_name = image.tempfile img = File.open(img_name, "r") {|io| io.read} conn = Faraday.new(api_uri) do |f| f.request :url_encoded f.request :multipart f.response :logger f.adapter :net_http end conn.headers["Authorization"] = api_public_key form_data = { image: Base64.encode64(img) } response = conn.post(endpoints[:image], form_data) result = JSON.parse(response.body) result end |