Class: Neocitizen::Client
- Inherits:
-
Object
- Object
- Neocitizen::Client
- Defined in:
- lib/neocitizen/client.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#info(sitename = nil) ⇒ Hash
Get info about a Neocities site.
-
#initialize(options = {}) ⇒ Hash
constructor
Build a new Neocitizen client.
-
#upload(*files) ⇒ Object
Upload one or more files to Neocities.
Constructor Details
#initialize(options = {}) ⇒ Hash
Build a new Neocitizen client.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/neocitizen/client.rb', line 17 def initialize( = {}) = { username: ENV["NEOCITIZEN_USERNAME"], password: ENV["NEOCITIZEN_PASSWORD"] }.merge() raise ArgumentError, "Username and password are required" unless [:username] && [:password] self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/neocitizen/client.rb', line 7 def @options end |
Instance Method Details
#info(sitename = nil) ⇒ Hash
Get info about a Neocities site
36 37 38 39 40 |
# File 'lib/neocitizen/client.rb', line 36 def info(sitename = nil) sitename ||= [:username] response = connection.get "/api/info", { sitename: sitename } MultiJson.load(response.body) end |
#upload(*files) ⇒ Object
Upload one or more files to Neocities
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/neocitizen/client.rb', line 50 def upload(*files) payload = files.inject({}) do |hash, filename| type = MimeMagic.by_path(filename) basename = File.basename(filename) hash[basename.to_sym] = Faraday::UploadIO.new(filename, type) hash end response = connection.post "/api/upload", payload MultiJson.load(response.body) end |