establish 0.0.26 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1565c65a2866c66db980533a1fd6e1487f53a6407aff769130f72c724997dc0
4
- data.tar.gz: 3375023d4ec987c1d2ee6c87cbd39191674a5b2fcfb390d3cd7c0a6dc9b67d7c
3
+ metadata.gz: a903044842b73b828911ed1f4834f63ad4e58b7cc2c32a0610380c44244503c6
4
+ data.tar.gz: 300bba595145f9e55748b0fb9eb306ecea46d44998bd1ea6b903181a7bf82ac9
5
5
  SHA512:
6
- metadata.gz: bf04845085479a3aae363a1be6b6b32106d9a3ebf18dd373df2db3e802eb8efeff983a0e35848ce934eabba8b21998e2653298590ff713ea22a4a35468070c5d
7
- data.tar.gz: f24bd4dc68af13149226ead11f61bacc7c1af43b2aff1f5bf5093c198d75815583993877b7c03ea586c27e47763a619f216ba6166fd86b11f7dd12f156569aac
6
+ metadata.gz: a9f186e0b65aa020ed0c2e5c8aff7e4af66898ebaa96eb004e26c887367219caa53cf27a7c095c5269c80098a4db013f0fc6532c1c018e4ac1c04cefd59e8a7c
7
+ data.tar.gz: 285ea4a771adc5fdbeade8f2eaa154a2321ae8fa806da8dd30108ee5b9cee8f3cd0698bf31abd8f3f6dd6944987ab741787b77fe3a49502274e0da478b0ffe44
@@ -1,8 +1,12 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  module Establish
4
+ class AppMetadataError < StandardError
5
+
6
+ end
7
+
4
8
  class AppMetadata
5
- APPLE_ITUNES_NAMESPACE = "http://apple.com/itunes/importer"
9
+ ITUNES_NAMESPACE = "http://apple.com/itunes/importer"
6
10
 
7
11
  attr_accessor :metadata_dir
8
12
 
@@ -28,9 +32,7 @@ module Establish
28
32
 
29
33
  # Update the app description which is shown in the AppStore
30
34
  def update_description(hash)
31
- raise "Please pass a hash of languages to this method" unless hash.kind_of?Hash
32
-
33
- # TODO: Implement
35
+ update_localized_value('description', hash)
34
36
  end
35
37
 
36
38
 
@@ -44,14 +46,60 @@ module Establish
44
46
  end
45
47
 
46
48
  private
47
- def modify_value(xpath, new_value)
48
- binding.pry
49
49
 
50
- @data.xpath("//x:#{xpath}", "x" => APPLE_ITUNES_NAMESPACE)
50
+ # Usage: '//x:keyword'
51
+ def fetch_value(xpath)
52
+ @data.xpath(xpath, "x" => ITUNES_NAMESPACE)
53
+ end
54
+
55
+ def update_localized_value(xpath_name, new_value)
56
+ raise "Please pass a hash of languages to this method" unless new_value.kind_of?Hash
57
+
58
+ fetch_value("//x:locale").each do |locale|
59
+ key = locale['name']
60
+ if new_value[key]
61
+ description_field = locale.search(xpath_name).first
62
+ if description_field.content != new_value[key]
63
+ description_field.content = new_value[key]
64
+ Helper.log.debug "Updated #{xpath_name} for locale #{locale}"
65
+ end
66
+ else
67
+ Helper.log.error "Could not find '#{xpath_name}' for #{key}. It was provided before. Not updating this value"
68
+ end
51
69
  end
70
+ end
52
71
 
72
+ # Parses the metadata using nokogiri
53
73
  def parse_package(path)
54
- @data ||= Nokogiri::XML(File.read("#{self.metadata_dir}/#{@app.apple_id}.itmsp/metadata.xml"))
74
+ @data ||= Nokogiri::XML(File.read("#{path}/#{@app.apple_id}.itmsp/metadata.xml"))
75
+ verify_package
76
+ clean_package
77
+ end
78
+
79
+ # Checks if there is a non live version available
80
+ # (a new version, or a new app)
81
+ def verify_package
82
+ versions = fetch_value("//x:version")
83
+
84
+ # TODO: This does not work for new apps
85
+ raise AppMetadataError.new("You have to create a new version before modifying the app metadata") if versions.count == 1
86
+
87
+ raise AppMetadataError.new("metadata_token is missing") if fetch_value("//x:metadata_token").count != 1
88
+ end
89
+
90
+ # Cleans up the package of stuff we do not want to modify/upload
91
+ def clean_package
92
+
93
+
94
+ # Remove the live version (if it exists)
95
+ versions = fetch_value("//x:version")
96
+ while versions.count > 1
97
+ versions.last.remove
98
+ versions = fetch_value("//x:version")
99
+ end
100
+ Helper.log.info "Modifying version '#{versions.first.attr('string')}' of app #{@app.app_identifier}"
101
+
102
+
55
103
  end
56
104
  end
57
- end
105
+ end
@@ -1,3 +1,3 @@
1
1
  module Establish
2
- VERSION = "0.0.26"
2
+ VERSION = "0.0.27"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: establish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincenzo Fehring