Module: FetchItunes

Defined in:
lib/FetchItunes.rb

Class Method Summary collapse

Class Method Details

.fetchObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/FetchItunes.rb', line 5

def self.fetch
  if ARGV.length==0 || ARGV == nil
    puts "error: Parameter does not match,there is not any parameter"
    return nil
  end
  arg_flags=ARGV
  flags=Array.new
  
  type_key="-type"
  type_value=nil

  name_key="-name"
  name_value=""

  id_key="-id"
  id_value=""

  apple_key="-apple"
  isApple=true

  all_info_key="-all"
  isAll=false
  
  limit_key="-count"
  limit_value = "200"
  
  help_key ="-h"
  
  arg_flags.each do |flag|
    if flag  == type_key 
       flag_content_index=arg_flags.index(flag) +1
       raise "args count not match !"   if arg_flags.count <= flag_content_index
       type_value=arg_flags[flag_content_index];
    elsif flag  == all_info_key 
       isAll=true
    elsif flag  == name_key
        flag_content_index=arg_flags.index(flag) +1
        raise "args name not match !"   if arg_flags.count <= flag_content_index
        name_value=arg_flags[flag_content_index];
        isApple=false
    elsif flag  == id_key
        flag_content_index=arg_flags.index(flag) +1
        raise "args id not match !"   if arg_flags.count <= flag_content_index
        id_value=arg_flags[flag_content_index];
        isApple =false
    elsif flag  == limit_key
        flag_content_index=arg_flags.index(flag) +1
        raise "args id not match !"   if arg_flags.count <= flag_content_index
        limit_value=arg_flags[flag_content_index];
    elsif flag  == help_key
        puts %/
fetchapp -[options] value
find apple app info! show apple by default!
options: 
name   : app name 
type   : app type [mac iphone ipad]
id     : app item id 
count  : show the count of items,default is 200
all    : show detail info
h      : help

note: if you can't use both of name and id at same time.
               
             /
        return 
    elsif flag.include? "-"
      puts "invalidate options. run fetchapp -h for help"
      return  
    end
  end
  
  #fetch content key
  track_name_key="trackName"
  track_id_key="trackId"
  niminum_os_version_key="minimumOsVersion"
  track_url_key="trackViewUrl"
  bundle_id_key="bundleId"
  version_key="version"
  price_key="price"
  
  request = HTTPItunesGetRequest.new
  if isApple
      request.item_id="284417353"
  elsif !id_value.nil?
      request.item_id=id_value
  end
  request.country="cn"
  request.entity="software"
  request.name=name_value
  request.limit=limit_value
  json_body= request.getItemInfos
  
  fetch_items= ConditionFetch.fetch_ios_apple(json_body,type_value)
  fetch_items.each do |item|
    name=item[track_name_key]
    track_id=item[track_id_key]
    niminum_version=item[niminum_os_version_key]
    track_url=item[track_url_key]
    bundle_id=item[bundle_id_key]
    version=item[version_key]
    price=item[price_key]
    
    space=" : "
    
    if isAll 
      puts "--------#{name}----------"
      puts track_id_key +   space + track_id.to_s
      puts niminum_os_version_key +   space + niminum_version
      puts track_url_key +   space + track_url
      puts bundle_id_key +   space + bundle_id.to_s
      puts version_key +   space + version
      puts price_key +   space + price
    elsif
      puts "------#{name}------#{bundle_id}---------"
    end
  end
end