Class: SmugMug::Client
- Inherits:
-
Object
- Object
- SmugMug::Client
- Defined in:
- lib/smugmug/client.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ Client
constructor
Creates a new client instance that can be used to access the SMugMug API.
-
#method_missing(method, *args) ⇒ Object
Direct mapping of SmugMug 1.3.0 API, either see wiki.smugmug.net/display/API/API+1.3.0 or the README for examples.
-
#upload_media(args) ⇒ Object
Uploading media files to SmugMug, see wiki.smugmug.net/display/API/Uploading for more information.
Constructor Details
#initialize(args) ⇒ Client
Creates a new client instance that can be used to access the SMugMug API
18 19 20 21 22 23 24 25 26 |
# File 'lib/smugmug/client.rb', line 18 def initialize(args) raise ArgumentError, "API Key required" unless args.has_key?(:api_key) raise ArgumentError, "API OAuth secret required" unless args.has_key?(:oauth_secret) raise ArgumentError, "Must specify the users OAuth datA" unless args[:user].is_a?(Hash) raise ArgumentError, "Users OAuth token required" unless args[:user][:token] raise ArgumentError, "Users OAuth secret token required" unless args[:user][:secret] @http = HTTP.new(args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Direct mapping of SmugMug 1.3.0 API, either see wiki.smugmug.net/display/API/API+1.3.0 or the README for examples
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/smugmug/client.rb', line 74 def method_missing(method, *args) api_cat = method.to_s return super unless SmugMug::API_METHODS[api_cat] if klass = self.instance_variable_get("@#{api_cat}_wrapper") klass else self.instance_variable_set("@#{api_cat}_wrapper", SmugMug::ApiCategory.new(@http, api_cat)) end end |
Instance Method Details
#upload_media(args) ⇒ Object
Uploading media files to SmugMug, see wiki.smugmug.net/display/API/Uploading for more information
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/smugmug/client.rb', line 48 def upload_media(args) raise ArgumentError, "File is required" unless args.has_key?(:file) raise ArgumentError, "AlbumID is required" unless args.has_key?(:AlbumID) if args[:file].is_a?(String) args[:FileName] ||= File.basename(args[:file]) args[:content] = File.read(args[:file]) elsif args[:file].is_a?(File) args[:FileName] ||= File.basename(args[:file].path) args[:content] = args[:file].read else raise ArgumentError, "File must be a String or File" end args.delete(:file) @http.request(:uploading, args) end |