Class: Appfront::API
- Inherits:
-
Object
- Object
- Appfront::API
- Defined in:
- lib/appfront/api.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ API
constructor
A new instance of API.
- #login ⇒ Object
- #method_missing(m, *args, &block) ⇒ Object
- #signup ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ API
Returns a new instance of API.
7 8 9 10 11 12 13 14 15 |
# File 'lib/appfront/api.rb', line 7 def initialize(opts = {}) @host = opts[:host] || 'https://api.appfront.io/v1' if opts[:email] and opts[:password] @email, @pass = opts[:email], opts[:password] else @email, @pass = Appfront::Command::Auth.credentials end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/appfront/api.rb', line 41 def method_missing(m, *args, &block) unless ['get', 'post', 'put', 'delete'].include? m.to_s raise NoMethodError, "undefined method: #{m}" end res = self.send('req', m, args) #TODO Da capire JSON.parse res rescue "" JSON.parse res rescue res end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
5 6 7 |
# File 'lib/appfront/api.rb', line 5 def email @email end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/appfront/api.rb', line 5 def host @host end |
Instance Method Details
#login ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/appfront/api.rb', line 17 def login return unless (@email && @pass) @pass = RestClient.post( "#{@host}/auth", email: @email, password: @pass ) rescue => e puts e.response exit 1 end |
#signup ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/appfront/api.rb', line 29 def signup return unless (@email && @pass) @pass = RestClient.post( "#{@host}/signup", email: @email, password: @pass ) rescue => e puts e.response exit 1 end |