phonegap-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "simplecov", ">= 0"
14
+ end
15
+
16
+ gem "httparty"
@@ -0,0 +1,42 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ httparty (0.8.1)
7
+ multi_json
8
+ multi_xml
9
+ jeweler (1.8.3)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rdoc
14
+ json (1.6.6)
15
+ multi_json (1.2.0)
16
+ multi_xml (0.4.2)
17
+ rake (0.9.2.2)
18
+ rdoc (3.12)
19
+ json (~> 1.4)
20
+ rspec (2.8.0)
21
+ rspec-core (~> 2.8.0)
22
+ rspec-expectations (~> 2.8.0)
23
+ rspec-mocks (~> 2.8.0)
24
+ rspec-core (2.8.0)
25
+ rspec-expectations (2.8.0)
26
+ diff-lcs (~> 1.1.2)
27
+ rspec-mocks (2.8.0)
28
+ simplecov (0.6.1)
29
+ multi_json (~> 1.0)
30
+ simplecov-html (~> 0.5.3)
31
+ simplecov-html (0.5.3)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.0.0)
38
+ httparty
39
+ jeweler (~> 1.8.3)
40
+ rdoc (~> 3.12)
41
+ rspec (~> 2.8.0)
42
+ simplecov
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Ian Morgan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ = phonegap-api
2
+
3
+ Ruby wrapper for the Phonegap build API.
4
+
5
+ https://build.phonegap.com
6
+ https://build.phonegap.com/docs/api
7
+
8
+ == Examples
9
+
10
+ Create connection
11
+
12
+ conn = Phonegap::Connection.new("username", "password")
13
+
14
+
15
+ List applications
16
+
17
+ conn.apps
18
+ => #<Phonegap::Apps:0x000001009d30e0 @apps=[#<Phonegap::App:0x000001009d3068 @repo="http://github.com/phonegap/phonegap-start.git", @download={"webos"=>"/api/v1/apps/94659/webos", "blackberry"=>"/api/v1/apps/94659/blackberry", "android"=>"/api/v1/apps/94659/android", "symbian"=>"/api/v1/apps/94659/symbian"}, title"PhoneGap: Getting Started", phonegap_version"1.5.0", privatefalse, role"admin", icon{"filename"=>"icon.png", "link"=>"/api/v1/apps/94659/icon"}, id94659, version"1.0.0", package"com.phonegap.getting.started", link"/api/v1/apps/94659", description"A template for getting started with PhoneGap development and build.phonegap.com", debugfalse, status{"webos"=>"complete", "ios"=>nil, "blackberry"=>"complete", "android"=>"complete", "symbian"=>"complete"}, error{}, build_count4], link"/api/v1/apps"
19
+
20
+
21
+ Build/Create sample application
22
+
23
+ conn.create_app(:title => 'API test app', :repo => 'https://github.com/alunny/phonegap-start.git', :create_method => 'remote_repo')
24
+
25
+
26
+ Delete application
27
+ conn.delete_app(94659)
28
+
29
+
30
+ == Contribute
31
+
32
+ Feel free to open pull requests. Please add tests for new features.
33
+
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2012 Ian Morgan. See LICENSE.txt for
38
+ further details.
39
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "phonegap-api"
18
+ gem.homepage = "http://github.com/seeingidog/phonegap-api"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ruby wrapper to the Phonegap build API}
21
+ gem.description = %Q{Ruby wrapper to the Phonegap build API}
22
+ gem.email = "ian@ruby-code.com"
23
+ gem.authors = ["Ian Morgan"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "phonegap-api #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,9 @@
1
+ require 'httparty'
2
+ dir = File.expand_path(File.join(File.dirname(__FILE__), 'phonegap-api'))
3
+ ['base','read','write', 'app', 'apps'].each do |req|
4
+ require File.join(dir, req)
5
+ end
6
+
7
+ module Phonegap
8
+ SUPPORTED_PLATFORMS = ["android", "blackberry", "ios", "symbian","webos"]
9
+ end
@@ -0,0 +1,18 @@
1
+ module Phonegap
2
+
3
+ class App
4
+ def initialize(api_data)
5
+ api_data.each do |k,v|
6
+ instance_variable_set(("@"+k).to_sym,v)
7
+ end
8
+ end
9
+
10
+ def to_json
11
+ hash = {}
12
+ instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
13
+ hash = {"data" => hash}
14
+ hash.to_json
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Phonegap
2
+
3
+ class Apps
4
+ def initialize(api_data)
5
+ @apps = []
6
+ api_data['apps'].each do |app|
7
+ @apps << App.new(app)
8
+ end
9
+ @link = api_data['link']
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ module Phonegap
2
+ class UnsupportedPlatformError < StandardError ; end
3
+ class APIError < StandardError ; end
4
+
5
+ class Connection
6
+ include HTTParty
7
+ base_uri 'https://build.phonegap.com/api/v1'
8
+ debug_output
9
+ follow_redirects false
10
+ format :json
11
+
12
+ def initialize(username, password)
13
+ @auth = {:basic_auth => {:username => username, :password => password}}
14
+ end
15
+
16
+ def get(url)
17
+ output = self.class.get(url, @auth).parsed_response
18
+ check_response!(output)
19
+ end
20
+
21
+ def post(url, body)
22
+ output = self.class.post(url, @auth.merge!({:body =>{:data => body}})).parsed_response
23
+ check_response!(output)
24
+ end
25
+
26
+ def put(url, body)
27
+ output = self.class.put(url, @auth.merge!({:body =>{:data => body}})).parsed_response
28
+ check_response!(output)
29
+ end
30
+
31
+ def delete(url)
32
+ output = self.class.delete(url, @auth).parsed_response
33
+ check_response!(output)
34
+ end
35
+
36
+ def check_response!(output)
37
+ raise APIError, output['error'] if output['error'].class == String
38
+ output
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,38 @@
1
+ module Phonegap
2
+ class Connection
3
+ def me
4
+ self.get("/me")
5
+ end
6
+
7
+ def apps
8
+ Apps.new(self.get("/apps"))
9
+ end
10
+
11
+ def get_app(app_id)
12
+ App.new(self.get("/apps/#{app_id}"))
13
+ end
14
+
15
+ def get_icon(app_id)
16
+ self.get("/apps/#{app_id}/icon")
17
+ end
18
+
19
+ def get_package_url(app_id, platform)
20
+ raise UnsupportedPlatformError unless SUPPORTED_PLATFORMS.include?(platform)
21
+ self.get("/apps/#{app_id}/#{platform}")['location']
22
+ end
23
+
24
+ def keys
25
+ self.get("/keys")
26
+ end
27
+
28
+ def keys_for_platform(platform)
29
+ raise UnsupportedPlatformError unless SUPPORTED_PLATFORMS.include?(platform)
30
+ self.get("/keys/#{platform}")
31
+ end
32
+
33
+ def get_key(platform, key_id)
34
+ raise UnsupportedPlatformError unless SUPPORTED_PLATFORMS.include?(platform)
35
+ self.get("/keys/#{platform}/#{key_id}")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ module Phonegap
2
+
3
+ class Connection
4
+ def create_app(params)
5
+ self.post("/apps", params)
6
+ end
7
+
8
+ def delete_app(app_id)
9
+ self.delete("/apps/#{app_id}")
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "phonegap-api"
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ian Morgan"]
12
+ s.date = "2012-04-09"
13
+ s.description = "Ruby wrapper to the Phonegap build API"
14
+ s.email = "ian@ruby-code.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/phonegap-api.rb",
29
+ "lib/phonegap-api/app.rb",
30
+ "lib/phonegap-api/apps.rb",
31
+ "lib/phonegap-api/base.rb",
32
+ "lib/phonegap-api/read.rb",
33
+ "lib/phonegap-api/write.rb",
34
+ "phonegap-api.gemspec",
35
+ "spec/phonegap-api_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = "http://github.com/seeingidog/phonegap-api"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.10"
42
+ s.summary = "Ruby wrapper to the Phonegap build API"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
50
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<httparty>, [">= 0"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
57
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
60
+ s.add_dependency(%q<simplecov>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<httparty>, [">= 0"])
64
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
65
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
68
+ s.add_dependency(%q<simplecov>, [">= 0"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+
4
+ describe "PhonegapApi" do
5
+ before(:each) do
6
+ @username = ""
7
+ @password = ""
8
+ @conn = Phonegap::Connection.new(@username, @password)
9
+ end
10
+
11
+ it "recieves information about current user" do
12
+ @conn.me.keys.should == ["apps", "keys", "username", "id", "link", "email"]
13
+ end
14
+
15
+ it "retrieves list of keys for account" do
16
+ @conn.keys.class.should == Hash
17
+ end
18
+
19
+ it "gets list of apps" do
20
+ @conn.apps.class.should == Phonegap::Apps
21
+ end
22
+
23
+ it "retrieves information about a specific app" do
24
+ @conn.get_app(94659).class.should == Phonegap::App
25
+ end
26
+
27
+ it "retrieves the URL to the app icon" do
28
+ @conn.get_icon(94659)["location"].class.should == String
29
+ end
30
+
31
+ it "retrieves the URL to the app icon" do
32
+ @conn.get_package_url(94659, "android").class.should == String
33
+ end
34
+
35
+ it "returns an App object from API return data" do
36
+ @conn.get_app(94659).class.should == Phonegap::App
37
+ end
38
+
39
+ it "returns json usable by the API from an App object" do
40
+ obj = @conn.get_app(94659)
41
+ obj.to_json.class.should == String
42
+ end
43
+
44
+ it "returns an Apps object composed of individual apps based on API return data" do
45
+ @conn.apps.class.should == Phonegap::Apps
46
+ end
47
+
48
+ it "creates an app" do
49
+ @app_id = @conn.create_app(:title => 'API test app', :repo => 'https://github.com/alunny/phonegap-start.git', :create_method => 'remote_repo')['id']
50
+ end
51
+
52
+ it "deletes the created app" do
53
+ @conn.delete_app(@app_id)
54
+ end
55
+
56
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'phonegap-api'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phonegap-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ian Morgan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &2157635300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157635300
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2157634420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2157634420
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ requirement: &2157633280 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.12'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2157633280
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &2157632060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2157632060
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &2157631100 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.8.3
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2157631100
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: &2157629780 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2157629780
80
+ description: Ruby wrapper to the Phonegap build API
81
+ email: ian@ruby-code.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.rdoc
87
+ files:
88
+ - .document
89
+ - .rspec
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - lib/phonegap-api.rb
97
+ - lib/phonegap-api/app.rb
98
+ - lib/phonegap-api/apps.rb
99
+ - lib/phonegap-api/base.rb
100
+ - lib/phonegap-api/read.rb
101
+ - lib/phonegap-api/write.rb
102
+ - phonegap-api.gemspec
103
+ - spec/phonegap-api_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: http://github.com/seeingidog/phonegap-api
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: 3213153322365656181
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 1.8.10
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Ruby wrapper to the Phonegap build API
133
+ test_files: []