phone_gap-build 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 899a79a1f62e5235bc0f9a1f216d3a9bbd72ca89
4
- data.tar.gz: 704aaa02c1219ff6077c4fd37c7201a81ff15d7c
3
+ metadata.gz: b7d9c20c29ac0055691fac9fabb28e826f8f4886
4
+ data.tar.gz: a62b82a3c032051c18b30335440c1b6bafb3a28c
5
5
  SHA512:
6
- metadata.gz: 00e0094338041ae7785c8b943eea9747e259b9922a19407d5ca5f1fd2867aae0cb4ef98608d721ac43e4d80d8dc18d5dc03b914c2679efae4c1b9571c5e3103d
7
- data.tar.gz: 2060ab63c6e1b05228f38ca2323b420100a41f01a6d709e7f52e4e6f3c64131091a79d3e0fc8df20ef140812486e7343a03373e52dc8a362f83957197c01402a
6
+ metadata.gz: b97eac4703677d6f6840ca14902520f82e4872d9e514f9d23a419b0b1bdccc9223ae62229d246002b80abb904f024f4deb95dbecf57f9b64cb2d1b8e760b5aa4
7
+ data.tar.gz: 20294eb0791f250b3916e1136b6c1fdc8f21485a7d1f5ff7b6d9b7612631379c7ede10e78ccc2a1ed5d734b80012ddf23bbdbfdd3444cedfc0dce95ac8b27d86
data/Rakefile CHANGED
@@ -2,4 +2,6 @@ require "bundler/gem_tasks"
2
2
 
3
3
  # for RSpec
4
4
  require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new('spec')
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => [:spec]
@@ -6,10 +6,23 @@ module PhoneGap
6
6
  class App < RestResource
7
7
 
8
8
  PATH = '/apps'
9
- attr_creatable :title, :create_method, :package, :version, :description, :debug, :keys, :private, :phonegap_version, :hydrates
10
- attr_updatable :title, :package, :version, :description, :debug, :private, :phonegap_version
11
9
 
10
+ attr_accessor :title, :create_method, :package, :version, :description, :debug, :keys, :private,
11
+ :phonegap_version, :hydrates, :file
12
+
13
+ attr_creatable :title, :create_method, :package, :version, :description, :debug, :keys, :private,
14
+ :phonegap_version, :hydrates, :file
15
+ attr_updatable :title, :package, :version, :description, :debug, :private, :phonegap_version
12
16
 
17
+ def post_options
18
+ if file
19
+ data_attributes = creatable_attributes
20
+ data_attributes.delete('@file')
21
+ {query: {file: file, data: as_json(only: data_attributes, remove_nils: true)}, detect_mime_type: true}
22
+ else
23
+ {query: {data: as_json(only: creatable_attributes, remove_nils: true)}}
24
+ end
25
+ end
13
26
  end
14
27
  end
15
28
  end
@@ -16,10 +16,11 @@ module PhoneGap
16
16
  end
17
17
 
18
18
  def create
19
- response = self.class.post(path, query: {data: as_json(only: creatable_attributes)})
19
+ response = self.class.post(path, post_options)
20
20
  if response.success?
21
21
  populate_from_json(JSON.parse(response.body))
22
22
  end
23
+ self
23
24
  end
24
25
 
25
26
  def update
@@ -36,17 +37,22 @@ module PhoneGap
36
37
 
37
38
  def as_json(params = {})
38
39
  if params[:only]
39
- params[:only].inject({}) do | memo, attribute_name|
40
+ json = params[:only].inject({}) do | memo, attribute_name|
40
41
  memo[attribute_name[1..-1].to_sym] = instance_variable_get(attribute_name)
41
42
  memo
42
43
  end
43
44
  else
44
- {}
45
+ json = {}
45
46
  end
47
+ params[:remove_nils] ? json.delete_if {|k, v| v.nil? } : json
46
48
  end
47
49
 
48
50
  private
49
51
 
52
+ def post_options
53
+ { query: { data: as_json(only: creatable_attributes) } }
54
+ end
55
+
50
56
  def path
51
57
  @id ? "#{self.class.const_get('PATH')}/#{@id}?auth_token=#{token}" : "#{self.class.const_get('PATH')}?auth_token=#{token}"
52
58
  end
@@ -56,7 +62,13 @@ module PhoneGap
56
62
  end
57
63
 
58
64
  def populate_from_json(json)
59
- self.class.new(json)
65
+ json.each do |key, value|
66
+ if respond_to?("#{key}=")
67
+ send("#{key}=", value)
68
+ else
69
+ instance_variable_set("@#{key}", value)
70
+ end
71
+ end
60
72
  end
61
73
  end
62
74
  end
@@ -1,5 +1,5 @@
1
1
  module PhoneGap
2
2
  module Build
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+
4
+ </head>
5
+ <body>
6
+ <p>Some content here</p>
7
+ </body>
8
+ </html>
@@ -11,7 +11,7 @@ describe PhoneGap::Build::App do
11
11
  subject { PhoneGap::Build::App }
12
12
 
13
13
  %w(title create_method package version description debug keys private phonegap_version hydrates).each do |attribute|
14
- it "'#{attribute}' is updatable" do
14
+ it "'#{attribute}' is creatable" do
15
15
  expect(subject.class_variable_get('@@creatable_attributes')[subject]).to include "@#{attribute}"
16
16
  end
17
17
  end
@@ -27,4 +27,40 @@ describe PhoneGap::Build::App do
27
27
  end
28
28
  end
29
29
  end
30
+
31
+ describe '#create' do
32
+
33
+ let(:response) { double('response', :success? => false) }
34
+
35
+ context 'when there are populated and non-populated creatable variables' do
36
+
37
+ before do
38
+ subject.title = 'title'
39
+ subject.create_method = 'create method'
40
+ subject.package = nil
41
+ end
42
+
43
+ it 'sends query data for all creatable attributes that do not have a value of nil' do
44
+ expected_options = { query: {data: { title: 'title', create_method: 'create method'}}}
45
+ expect(subject.class).to receive(:post).with(anything, expected_options ).and_return response
46
+ subject.create
47
+ end
48
+
49
+ context 'when a file is present' do
50
+
51
+ let(:file) { fixture_file('index.html') }
52
+
53
+ before do
54
+ subject.file = file
55
+ end
56
+
57
+ it 'sends the file through as part of the query' do
58
+ expected_options =
59
+ { query: { file: file, data: {title: 'title', create_method: 'create method'}}, detect_mime_type: true}
60
+ expect(subject.class).to receive(:post).with(anything, expected_options).and_return response
61
+ subject.create
62
+ end
63
+ end
64
+ end
65
+ end
30
66
  end
@@ -16,7 +16,7 @@ describe PhoneGap::Build::RestResource do
16
16
 
17
17
  class Child < PhoneGap::Build::RestResource
18
18
 
19
- attr_accessor :id
19
+ attr_accessor :id, :file
20
20
 
21
21
  PATH = 'users'
22
22
 
@@ -42,10 +42,27 @@ describe PhoneGap::Build::RestResource do
42
42
  subject.create
43
43
  end
44
44
 
45
+ context 'child class has #post_options' do
46
+
47
+ let(:post_options) { lambda{ 'wonder woman'} }
48
+
49
+ before do
50
+ subject.define_singleton_method(:post_options, post_options)
51
+ end
52
+
53
+ it 'posts using options from the child class' do
54
+ expect(subject.class).to receive(:post).with(anything, 'wonder woman').and_return response
55
+ subject.create
56
+ end
57
+ end
58
+
59
+ context 'child class does not have #post_options' do
60
+
45
61
  it 'sends a body containing all the json representation of the object' do
46
- expect(subject.class).to receive(:post).with(anything(), query: {data: {}}).and_return response
62
+ expect(subject.class).to receive(:post).with(anything, query: {data: subject.as_json}).and_return response
47
63
  subject.create
48
64
  end
65
+ end
49
66
 
50
67
  context 'after successful creation' do
51
68
 
@@ -57,7 +74,7 @@ describe PhoneGap::Build::RestResource do
57
74
 
58
75
  it 'updates the object with any response attributes' do
59
76
  response = subject.create
60
- expect(response).to be_kind_of Child
77
+ expect(response.object_id).to be subject.object_id
61
78
  expect(response.instance_variable_get('@title')).to eq 'Batman'
62
79
  expect(response.instance_variable_get('@rating')).to eq 5
63
80
  end
@@ -3,4 +3,8 @@ require 'json'
3
3
  def response_body_for(request)
4
4
  fixture_file = File.open(ROOT_DIR + "fixtures/api_responses/#{request}.json")
5
5
  File.read(fixture_file)
6
+ end
7
+
8
+ def fixture_file(filename)
9
+ File.new(ROOT_DIR + "fixtures/#{filename}")
6
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phone_gap-build
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seb Glazebrook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-13 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httmultiparty
@@ -102,6 +102,7 @@ files:
102
102
  - phone_gap-build.gemspec
103
103
  - spec/fixtures/api_responses/get-apps.json
104
104
  - spec/fixtures/api_responses/rest-resource-create.json
105
+ - spec/fixtures/index.html
105
106
  - spec/phone_gap/build/app_spec.rb
106
107
  - spec/phone_gap/build/rest_resource_spec.rb
107
108
  - spec/phone_gap/build_spec.rb
@@ -134,6 +135,7 @@ summary: PhoneGap Build Api gem
134
135
  test_files:
135
136
  - spec/fixtures/api_responses/get-apps.json
136
137
  - spec/fixtures/api_responses/rest-resource-create.json
138
+ - spec/fixtures/index.html
137
139
  - spec/phone_gap/build/app_spec.rb
138
140
  - spec/phone_gap/build/rest_resource_spec.rb
139
141
  - spec/phone_gap/build_spec.rb