supermarket 0.0.1-universal-java

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+
2
+ # Supermarket
3
+
4
+ This is a thin JRuby wrapper for the [Android Market API](http://code.google.com/p/android-market-api/) Java project (also mirrored on github: [jberkel/android-market-api](http://github.com/jberkel/android-market-api/)).
5
+
6
+ It's a new project and only some parts of the protocol have been implemented. I decided to build on top of Java/JRuby because the native Ruby Protocolbuffer implementation ([ruby-protobuf](http://code.google.com/p/ruby-protobuf/)) could not properly handle the [.proto file](http://github.com/jberkel/android-market-api/blob/master/AndroidMarketApi/proto/market.proto) used by the API.
7
+
8
+ ## Synopis
9
+ require 'supermarket'
10
+ session = Supermarket::Session.new
11
+
12
+ # search apps for term 'foo' return results as json
13
+ puts session.search("foo").to_json
14
+
15
+ # retrieve comments for an app by app id as xml
16
+ puts session.comments("com.example.my.project").to_xml
17
+
18
+
19
+ ## Installation
20
+
21
+ $ gem install supermarket
22
+
23
+ You will need to provide your Google market credentials in ~/.supermarket.yml:
24
+
25
+ ---
26
+ login: foo@gmail.com
27
+ password: secret
28
+
29
+ ## Command line usage
30
+
31
+ ### Searching
32
+
33
+ $ market search ruboto | jsonpretty
34
+ {
35
+ "app": [
36
+ {
37
+ "rating": "4.642857142857143",
38
+ "title": "Ruboto IRB",
39
+ "ratingsCount": 14,
40
+ "creator": "Jan Berkel",
41
+ "appType": "APPLICATION",
42
+ "id": "9089465703133677000",
43
+ "packageName": "org.jruby.ruboto.irb",
44
+ "version": "0.1",
45
+ "versionCode": 1,
46
+ "creatorId": "\"Jan Berkel\"",
47
+ "ExtendedInfo": {
48
+ "category": "Tools",
49
+ "permissionId": [
50
+
51
+
52
+ ...
53
+
54
+ ### Comments
55
+
56
+ $ market comments org.jruby.ruboto.irb | jsonpretty
57
+ {
58
+ "comments": [
59
+ {
60
+ "rating": 5,
61
+ "creationTime": 1269710736815,
62
+ "authorName": "Nate Kidwell",
63
+ "text": "Tremendous application. More examples would be great (as would integrated rubydocs), but awesome all the same.",
64
+ "authorId": "04441815096871118032"
65
+ },
66
+
67
+ ...
68
+
69
+ ### Screenshot
70
+
71
+ $ market imagedata org.jruby.ruboto.irb --image-out=image.jpg
72
+
73
+ ## Credits
74
+
75
+ This library would be impossible without the code from the [Android Market API](http://code.google.com/p/android-market-api/) project. Serialization support handled by the [protobuf-java-format](http://code.google.com/p/protobuf-java-format/) library.
76
+
77
+ ## License
78
+
79
+ Copyright (c) 2010, Jan Berkel <jan.berkel@gmail.com>
80
+ All rights reserved.
81
+
82
+ Redistribution and use in source and binary forms, with or without
83
+ modification, are permitted provided that the following conditions are met:
84
+ * Redistributions of source code must retain the above copyright
85
+ notice, this list of conditions and the following disclaimer.
86
+ * Redistributions in binary form must reproduce the above copyright
87
+ notice, this list of conditions and the following disclaimer in the
88
+ documentation and/or other materials provided with the distribution.
89
+
90
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY
91
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
92
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
93
+ DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
94
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
95
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
96
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
97
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
98
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
99
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/bin/market ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env jruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
3
+
4
+ require 'supermarket'
5
+ format = ARGV.map { |a| a[/--format=(\w+)/, 1]}.compact.first || "json"
6
+ image = ARGV.map { |a| a[/--image-out=([^\s]+)/, 1]}.compact.first || "image.jpg"
7
+
8
+ def usage
9
+ puts "#{File.basename($0)} [search|comments|image|imagedata] [query|app_id] [--format=json|xml|html] [--image-out=file]"
10
+ exit 1
11
+ end
12
+
13
+ case command = ARGV.shift
14
+ when /\A(search|comments|image)\Z/
15
+ arg = ARGV.shift or usage
16
+ puts Supermarket::Session.new.send(command, arg).send("to_#{format.downcase}")
17
+ when 'imagedata'
18
+ arg = ARGV.shift or usage
19
+ File.open(image, 'w') { |f| f << Supermarket::Session.new.image_data(arg) }
20
+ else usage
21
+ end
22
+
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + "/jars/protobuf-format-java-1.2-SNAPSHOT.jar"
2
+
3
+
4
+ #Serialize protobuf to different formats using
5
+ #http://code.google.com/p/protobuf-java-format/
6
+ module Supermarket
7
+ module Formats
8
+ import 'com.google.protobuf.JsonFormat'
9
+ import 'com.google.protobuf.XmlFormat'
10
+ import 'com.google.protobuf.HtmlFormat'
11
+
12
+ def to_json
13
+ JsonFormat.printToString(self)
14
+ end
15
+
16
+ def to_xml
17
+ XmlFormat.printToString(self)
18
+ end
19
+
20
+ def to_html
21
+ HtmlFormat.printToString(self)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env jruby
2
+ require 'java'
3
+ require 'yaml'
4
+
5
+ require File.dirname(__FILE__) + "/jars/AndroidMarketApi.jar"
6
+ require File.dirname(__FILE__) + "/jars/protobuf-java-2.2.0.jar"
7
+ require File.dirname(__FILE__) + "/formats"
8
+
9
+ #A thin Ruby wrapper around the Java based Android Market API
10
+ #http://code.google.com/p/android-market-api/
11
+ module Supermarket
12
+ import 'com.gc.android.market.api.MarketSession'
13
+ import 'com.gc.android.market.api.model.Market'
14
+
15
+ [Market::CommentsResponse, Market::AppsResponse, Market::GetImageResponse].each do |msg|
16
+ msg.send(:include, Formats)
17
+ end
18
+
19
+ class Session
20
+ attr_reader :_session
21
+
22
+ def initialize
23
+ @_session = MarketSession.new
24
+ @_session.login(config['login'], config['password'])
25
+ end
26
+
27
+ def config_file
28
+ File.join(ENV['HOME'], '.supermarket.yml')
29
+ end
30
+
31
+ def config
32
+ @config ||= begin
33
+ unless File.exists?(config_file)
34
+ File.open(config_file, 'w') { |f| f << YAML.dump('login'=>'someone@gmail.com', 'password'=>'secr3t') }
35
+ raise "Android market config file not found. Please edit #{config_file}"
36
+ end
37
+ YAML.load_file(config_file)
38
+ end
39
+ end
40
+
41
+
42
+ def search(query, extended=true, start=0, count=10)
43
+ request = Market::AppsRequest.newBuilder().
44
+ setQuery(query).
45
+ setStartIndex(start).
46
+ setEntriesCount(count).
47
+ setWithExtendedInfo(extended).build()
48
+ execute(request)
49
+ end
50
+
51
+
52
+ def comments(app_id, start=0, count=10)
53
+ raise ArgumentError, "need app id" unless app_id
54
+
55
+ request = Market::CommentsRequest.newBuilder().
56
+ setAppId(app_id).
57
+ setStartIndex(start).
58
+ setEntriesCount(count).build()
59
+
60
+ if resp = execute(request)
61
+ resp
62
+ else
63
+ []
64
+ end
65
+ end
66
+
67
+ def image(app_id, usage=Market::GetImageRequest::AppImageUsage::SCREENSHOT, image_id='1')
68
+ request = Market::GetImageRequest.newBuilder().
69
+ setAppId(pkg_to_app_id(app_id)).
70
+ setImageUsage(usage).
71
+ setImageId(image_id).build()
72
+
73
+ execute(request)
74
+ end
75
+
76
+ def image_data(app_id, usage=Market::GetImageRequest::AppImageUsage::SCREENSHOT, image_id='1')
77
+ if resp = image(app_id, usage, image_id)
78
+ String.from_java_bytes(resp.getImageData().toByteArray())
79
+ else
80
+ []
81
+ end
82
+ end
83
+
84
+ # Resolves a package name to a package id
85
+ def pkg_to_app_id(package)
86
+ return package if package =~ /\A-?\d+\Z/
87
+
88
+ if app = search(package).getAppList().to_a.find { |app| app.packageName == package }
89
+ app.getId()
90
+ else
91
+ raise ArgumentError, "could not resolve package #{package}"
92
+ end
93
+ end
94
+
95
+ protected
96
+ def execute(request)
97
+ response = nil
98
+ _session.append(request) do |ctxt, resp|
99
+ response = resp
100
+ end
101
+ _session.flush
102
+ response
103
+ end
104
+ end
105
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'supermarket', 'session')
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: supermarket
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: universal-java
11
+ authors:
12
+ - Jan Berkel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-28 00:00:00 +01:00
18
+ default_executable: market
19
+ dependencies: []
20
+
21
+ description: An unoffical/reverse engineered API for Android market.
22
+ email: jan.berkel@gmail.com
23
+ executables:
24
+ - market
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.md
29
+ files:
30
+ - bin/market
31
+ - lib/supermarket.rb
32
+ - lib/supermarket/formats.rb
33
+ - lib/supermarket/jars/AndroidMarketApi.jar
34
+ - lib/supermarket/jars/protobuf-format-java-1.2-SNAPSHOT.jar
35
+ - lib/supermarket/jars/protobuf-java-2.2.0.jar
36
+ - lib/supermarket/session.rb
37
+ - README.md
38
+ has_rdoc: true
39
+ homepage: http://github.com/jberkel/supermarket
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.6
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: JRuby bindings for android-market-api
68
+ test_files: []
69
+