Class: Phonegap::Connection
- Inherits:
-
Object
- Object
- Phonegap::Connection
- Includes:
- HTTParty
- Defined in:
- lib/phonegap-api/base.rb,
lib/phonegap-api/read.rb,
lib/phonegap-api/write.rb
Instance Method Summary collapse
- #apps ⇒ Object
- #check_response!(output) ⇒ Object
- #create_app(params) ⇒ Object
- #delete(url) ⇒ Object
- #delete_app(app_id) ⇒ Object
- #get(url) ⇒ Object
- #get_app(app_id) ⇒ Object
- #get_icon(app_id) ⇒ Object
- #get_key(platform, key_id) ⇒ Object
- #get_package_url(app_id, platform) ⇒ Object
-
#initialize(*auth) ⇒ Connection
constructor
A new instance of Connection.
- #keys ⇒ Object
- #keys_for_platform(platform) ⇒ Object
- #me ⇒ Object
- #post(url, body) ⇒ Object
- #put(url, body) ⇒ Object
Constructor Details
#initialize(*auth) ⇒ Connection
Returns a new instance of Connection.
11 12 13 14 15 16 17 |
# File 'lib/phonegap-api/base.rb', line 11 def initialize(*auth) if auth.any? @auth = {:basic_auth => auth.first} else @auth = {:basic_auth => YAML.load_file("config/phonegap.yml")} end end |
Instance Method Details
#apps ⇒ Object
7 8 9 |
# File 'lib/phonegap-api/read.rb', line 7 def apps Apps.new(self.get("/apps")) end |
#check_response!(output) ⇒ Object
39 40 41 42 43 |
# File 'lib/phonegap-api/base.rb', line 39 def check_response!(output) raise APIError, output['error'] if output['error'].class == String output end |
#create_app(params) ⇒ Object
4 5 6 |
# File 'lib/phonegap-api/write.rb', line 4 def create_app(params) self.post("/apps", params) end |
#delete(url) ⇒ Object
34 35 36 37 |
# File 'lib/phonegap-api/base.rb', line 34 def delete(url) output = self.class.delete(url, @auth) check_response!(output).parsed_response end |
#delete_app(app_id) ⇒ Object
8 9 10 |
# File 'lib/phonegap-api/write.rb', line 8 def delete_app(app_id) self.delete("/apps/#{app_id}") end |
#get(url) ⇒ Object
19 20 21 22 |
# File 'lib/phonegap-api/base.rb', line 19 def get(url) output = self.class.get(url, @auth) check_response!(output).parsed_response end |
#get_app(app_id) ⇒ Object
11 12 13 |
# File 'lib/phonegap-api/read.rb', line 11 def get_app(app_id) App.new(self.get("/apps/#{app_id}")) end |
#get_icon(app_id) ⇒ Object
15 16 17 |
# File 'lib/phonegap-api/read.rb', line 15 def get_icon(app_id) self.get("/apps/#{app_id}/icon") end |
#get_key(platform, key_id) ⇒ Object
33 34 35 36 |
# File 'lib/phonegap-api/read.rb', line 33 def get_key(platform, key_id) raise UnsupportedPlatformError unless SUPPORTED_PLATFORMS.include?(platform) self.get("/keys/#{platform}/#{key_id}") end |
#get_package_url(app_id, platform) ⇒ Object
19 20 21 22 |
# File 'lib/phonegap-api/read.rb', line 19 def get_package_url(app_id, platform) raise UnsupportedPlatformError unless SUPPORTED_PLATFORMS.include?(platform) self.get("/apps/#{app_id}/#{platform}")['location'] end |
#keys ⇒ Object
24 25 26 |
# File 'lib/phonegap-api/read.rb', line 24 def keys self.get("/keys") end |
#keys_for_platform(platform) ⇒ Object
28 29 30 31 |
# File 'lib/phonegap-api/read.rb', line 28 def keys_for_platform(platform) raise UnsupportedPlatformError unless SUPPORTED_PLATFORMS.include?(platform) self.get("/keys/#{platform}") end |
#me ⇒ Object
3 4 5 |
# File 'lib/phonegap-api/read.rb', line 3 def me self.get("/me") end |
#post(url, body) ⇒ Object
24 25 26 27 |
# File 'lib/phonegap-api/base.rb', line 24 def post(url, body) output = self.class.post(url, @auth.merge!({:body =>{:data => body}})) check_response!(output).parsed_response end |
#put(url, body) ⇒ Object
29 30 31 32 |
# File 'lib/phonegap-api/base.rb', line 29 def put(url, body) output = self.class.put(url, @auth.merge!({:body =>{:data => body}})) check_response!(output).parsed_response end |