crawlora-googleplay 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 816eb4c2fe04aefdbe59426a59ceba32b6752926620a49edbed3a8ec7213b738
4
+ data.tar.gz: 821154c5d53cbbf85bfa705c639fcf5336aa516ea93c5e1680dc071065b06b05
5
+ SHA512:
6
+ metadata.gz: fb64b337c7218937e0230dcc831873dc307fe914a72d5ac77b70177c0044cfed833690299d10a3b61e4053ce5322d1959d8351abb88c074a095c14211402854e
7
+ data.tar.gz: 6c6bccf85829c2f12216937f254a49cbef097e130cad06acd75a00082014352fde57928ccee861ae4b72b417e360f0e7ca304b84e3cadb724642b976193be218
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial focused Google Play Ruby client for Crawlora's hosted API.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Crawlora
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Crawlora Google Play Ruby client
2
+
3
+ This gem calls the Crawlora hosted API at `https://api.crawlora.net/api/v1`. It does not call or scrape Google Play directly. Requests require your Crawlora API key and use your account's service plan.
4
+
5
+ ## Install
6
+
7
+ ```ruby
8
+ gem "crawlora-googleplay"
9
+ ```
10
+
11
+ Create an account at [crawlora.net](https://crawlora.net/signup?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=googleplay-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=googleplay-ruby-console) to get an API key, and set `CRAWLORA_API_KEY` before running the client:
12
+
13
+ ```ruby
14
+ require "json"
15
+ require "crawlora/googleplay"
16
+
17
+ client = Crawlora::Googleplay::Client.new
18
+ result = client.request("googleplay-search", JSON.parse("{\"term\": \"sample\"}"))
19
+ puts result
20
+ client.close
21
+ ```
22
+
23
+ Use an operation-specific method for normal calls. `request(operation_id, params = {}, response_type: :auto)` is available for every operation. `response_type: :text` returns raw response text. This gem includes 11 API operations.
24
+
25
+ ```ruby
26
+ client = Crawlora::Googleplay::Client.new(api_key: ENV.fetch("CRAWLORA_API_KEY"), timeout: 30)
27
+ # client.<operation_method>(<endpoint parameters>)
28
+ client.close
29
+ ```
30
+
31
+ Client options include `api_key`, `base_url`, and `timeout`. Ruby stdlib provides the HTTP and JSON support.
32
+
33
+ See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=googleplay-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=googleplay-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-googleplay) for account setup, the API operation reference, and release history.
@@ -0,0 +1,240 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module Crawlora
6
+ module Googleplay
7
+ module Errors
8
+ class Error < StandardError
9
+ attr_reader :status, :operation_id, :body
10
+
11
+ def initialize(message, status: nil, operation_id: nil, body: nil)
12
+ super(message)
13
+ @status, @operation_id, @body = status, operation_id, body
14
+ end
15
+ end
16
+ class ClientError < Error; end
17
+ class ServerError < Error; end
18
+ class NetworkError < Error; end
19
+ end
20
+
21
+ OPERATIONS = JSON.parse(<<~'JSON').freeze
22
+ {"googleplay-app": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-app", "method": "GET", "params": [{"description": "Google Play package name", "in": "query", "name": "app_id", "required": true, "type": "string", "x-example": "com.openai.chatgpt"}, {"description": "Two-letter storefront country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}], "path": "/googleplay/app", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "app_id", "required": true, "type": "string"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}], "security": ["ApiKeyAuth"]}, "googleplay-categories": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-categories", "method": "GET", "params": [{"description": "Two-letter country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}], "path": "/googleplay/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}], "security": ["ApiKeyAuth"]}, "googleplay-datasafety": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-datasafety", "method": "GET", "params": [{"description": "Google Play app id", "in": "query", "name": "app_id", "required": true, "type": "string", "x-example": "com.openai.chatgpt"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}], "path": "/googleplay/datasafety", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "app_id", "required": true, "type": "string"}, {"in": "query", "name": "lang", "type": "string"}], "security": ["ApiKeyAuth"]}, "googleplay-developer": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-developer", "method": "GET", "params": [{"description": "Developer id or name", "in": "path", "name": "dev_id", "required": true, "type": "string", "x-example": "OpenAI"}, {"description": "Number of apps", "in": "query", "name": "num", "type": "integer", "x-example": 60}, {"description": "Two-letter country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}, {"default": false, "description": "Resolve each app to full detail", "in": "query", "name": "full_detail", "type": "boolean"}], "path": "/googleplay/developer/{dev_id}", "pathParams": ["dev_id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "num", "type": "integer"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}, {"in": "query", "name": "full_detail", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "googleplay-list": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-list", "method": "GET", "params": [{"description": "Collection: TOP_FREE, TOP_PAID, GROSSING, NEW_FREE, NEW_PAID", "enum": ["TOP_FREE", "TOP_PAID", "GROSSING", "NEW_FREE", "NEW_PAID"], "in": "query", "name": "collection", "type": "string", "x-example": "TOP_FREE"}, {"description": "Category id", "in": "query", "name": "category", "type": "string", "x-example": "TOOLS"}, {"description": "Google Play device tab: phone, tablet, tv, chromebook, watch, xr, car", "enum": ["phone", "tablet", "tv", "chromebook", "watch", "xr", "car"], "in": "query", "name": "device", "type": "string", "x-example": "tablet"}, {"description": "Family age range", "in": "query", "name": "age", "type": "string", "x-example": "AGE_RANGE1"}, {"description": "Number of apps", "in": "query", "name": "num", "type": "integer", "x-example": 50}, {"description": "Two-letter country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}, {"default": false, "description": "Resolve each app to full detail", "in": "query", "name": "full_detail", "type": "boolean"}], "path": "/googleplay/list", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["TOP_FREE", "TOP_PAID", "GROSSING", "NEW_FREE", "NEW_PAID"], "in": "query", "name": "collection", "type": "string"}, {"in": "query", "name": "category", "type": "string"}, {"enum": ["phone", "tablet", "tv", "chromebook", "watch", "xr", "car"], "in": "query", "name": "device", "type": "string"}, {"in": "query", "name": "age", "type": "string"}, {"in": "query", "name": "num", "type": "integer"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}, {"in": "query", "name": "full_detail", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "googleplay-permissions": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-permissions", "method": "GET", "params": [{"description": "Google Play app id", "in": "query", "name": "app_id", "required": true, "type": "string", "x-example": "com.openai.chatgpt"}, {"description": "Two-letter country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}, {"default": false, "description": "Return only permission names", "in": "query", "name": "short", "type": "boolean"}], "path": "/googleplay/permissions", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "app_id", "required": true, "type": "string"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}, {"in": "query", "name": "short", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "googleplay-ratings": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-ratings", "method": "GET", "params": [{"description": "Google Play package name", "in": "query", "name": "app_id", "required": true, "type": "string", "x-example": "com.openai.chatgpt"}, {"description": "Two-letter storefront country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}], "path": "/googleplay/ratings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "app_id", "required": true, "type": "string"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}], "security": ["ApiKeyAuth"]}, "googleplay-reviews": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-reviews", "method": "GET", "params": [{"description": "Google Play app id", "in": "query", "name": "app_id", "required": true, "type": "string", "x-example": "com.openai.chatgpt"}, {"description": "Sort: helpfulness, newest, rating", "enum": ["helpfulness", "newest", "rating"], "in": "query", "name": "sort", "type": "string", "x-example": "newest"}, {"description": "Number of reviews", "in": "query", "name": "num", "type": "integer", "x-example": 100}, {"description": "Two-letter country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}, {"default": false, "description": "Only fetch the requested page", "in": "query", "name": "paginate", "type": "boolean"}, {"description": "Token from a previous response", "in": "query", "name": "next_pagination_token", "type": "string"}], "path": "/googleplay/reviews", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "app_id", "required": true, "type": "string"}, {"enum": ["helpfulness", "newest", "rating"], "in": "query", "name": "sort", "type": "string"}, {"in": "query", "name": "num", "type": "integer"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}, {"in": "query", "name": "paginate", "type": "boolean"}, {"in": "query", "name": "next_pagination_token", "type": "string"}], "security": ["ApiKeyAuth"]}, "googleplay-search": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-search", "method": "GET", "params": [{"description": "Search term", "in": "query", "name": "term", "required": true, "type": "string", "x-example": "chatgpt"}, {"description": "Number of apps", "in": "query", "name": "num", "type": "integer", "x-example": 20}, {"description": "Two-letter country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}, {"default": false, "description": "Resolve each app to full detail", "in": "query", "name": "full_detail", "type": "boolean"}, {"description": "Price filter: all, free, paid", "enum": ["all", "free", "paid"], "in": "query", "name": "price", "type": "string", "x-example": "all"}], "path": "/googleplay/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "term", "required": true, "type": "string"}, {"in": "query", "name": "num", "type": "integer"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}, {"in": "query", "name": "full_detail", "type": "boolean"}, {"enum": ["all", "free", "paid"], "in": "query", "name": "price", "type": "string"}], "security": ["ApiKeyAuth"]}, "googleplay-similar": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-similar", "method": "GET", "params": [{"description": "Google Play app id", "in": "query", "name": "app_id", "required": true, "type": "string", "x-example": "com.openai.chatgpt"}, {"description": "Number of apps", "in": "query", "name": "num", "type": "integer", "x-example": 24}, {"description": "Two-letter country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}, {"default": false, "description": "Resolve each app to full detail", "in": "query", "name": "full_detail", "type": "boolean"}], "path": "/googleplay/similar", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "app_id", "required": true, "type": "string"}, {"in": "query", "name": "num", "type": "integer"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}, {"in": "query", "name": "full_detail", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "googleplay-suggest": {"bodyParam": null, "bodyRequired": false, "id": "googleplay-suggest", "method": "GET", "params": [{"description": "Search term prefix", "in": "path", "name": "term", "required": true, "type": "string", "x-example": "chatg"}, {"description": "Two-letter country code", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Two-letter language code", "in": "query", "name": "lang", "type": "string", "x-example": "en"}], "path": "/googleplay/suggest/{term}", "pathParams": ["term"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}], "security": ["ApiKeyAuth"]}}
23
+ JSON
24
+ OPERATION_IDS = JSON.parse(<<~'JSON').freeze
25
+ ["googleplay-app", "googleplay-categories", "googleplay-datasafety", "googleplay-developer", "googleplay-list", "googleplay-permissions", "googleplay-ratings", "googleplay-reviews", "googleplay-search", "googleplay-similar", "googleplay-suggest"]
26
+ JSON
27
+ OPERATION_COUNT = OPERATION_IDS.length
28
+
29
+ class Client
30
+ attr_reader :base_url
31
+
32
+ def initialize(api_key: ENV["CRAWLORA_API_KEY"], base_url: "https://api.crawlora.net/api/v1", timeout: 30, user_agent: "crawlora-googleplay-ruby/0.1.0", transport: nil)
33
+ @api_key = api_key
34
+ @base_url = base_url.to_s.sub(%r{/+$}, "")
35
+ @timeout = Float(timeout)
36
+ @user_agent = user_agent
37
+ @transport = transport
38
+ @closed = false
39
+ end
40
+
41
+ def request(operation_id, params = {}, response_type: :auto)
42
+ raise Errors::ClientError, "client is closed" if @closed
43
+ operation_id = operation_id.to_s
44
+ operation = OPERATIONS[operation_id]
45
+ raise Errors::ClientError.new("unknown operation: #{operation_id}", operation_id: operation_id) unless operation
46
+ raise Errors::ClientError.new("Crawlora API key is required", operation_id: operation_id) if @api_key.nil? || @api_key.to_s.empty?
47
+ normalized = params.each_with_object({}) { |(key, value), out| out[key.to_s] = value }
48
+ payload = request_body(operation, normalized)
49
+ url = build_url(operation, normalized)
50
+ uri = URI.parse(url)
51
+ request = operation["method"] == "POST" ? Net::HTTP::Post.new(uri) : Net::HTTP::Get.new(uri)
52
+ unless payload.nil?
53
+ request.body = payload
54
+ request["Content-Type"] = "application/json"
55
+ end
56
+ request["x-api-key"] = @api_key
57
+ request["User-Agent"] = @user_agent
58
+ request["Accept"] = operation["produces"].include?("text/plain") ? "application/json, text/plain" : "application/json"
59
+ begin
60
+ if @transport
61
+ response = if operation["method"] == "POST"
62
+ @transport.call(url, request.to_hash, @timeout, "POST", payload)
63
+ else
64
+ @transport.call(url, request.to_hash, @timeout)
65
+ end
66
+ status = Integer(response.fetch(:status) { response.fetch("status") })
67
+ body = response.fetch(:body) { response.fetch("body", "") }
68
+ headers = response.fetch(:headers) { response.fetch("headers", {}) }
69
+ content_type = headers["content-type"] || headers["Content-Type"]
70
+ else
71
+ http = Net::HTTP.new(uri.host, uri.port)
72
+ http.use_ssl = uri.scheme == "https"
73
+ http.open_timeout = @timeout
74
+ http.read_timeout = @timeout
75
+ response = http.start { |connection| connection.request(request) }
76
+ status = response.code.to_i
77
+ body = response.body
78
+ content_type = response["content-type"]
79
+ end
80
+ rescue Timeout::Error, SocketError, SystemCallError, IOError, EOFError, Net::HTTPBadResponse, Net::ProtocolError, OpenSSL::SSL::SSLError => error
81
+ raise Errors::NetworkError.new("Crawlora request failed: #{error.message}", operation_id: operation_id)
82
+ end
83
+ unless status >= 200 && status < 300
84
+ klass = status >= 500 ? Errors::ServerError : Errors::ClientError
85
+ raise klass.new("Crawlora returned HTTP #{status}", status: status, operation_id: operation_id, body: body)
86
+ end
87
+ parse_response(body, content_type, operation, normalized, response_type)
88
+ end
89
+
90
+ def close
91
+ @closed = true
92
+ end
93
+
94
+ def closed?
95
+ @closed
96
+ end
97
+
98
+ def with
99
+ return self unless block_given?
100
+ yield self
101
+ ensure
102
+ close if block_given?
103
+ end
104
+
105
+ def self.operation_count
106
+ OPERATION_COUNT
107
+ end
108
+
109
+ def self.operation_ids
110
+ OPERATION_IDS
111
+ end
112
+
113
+ def self.operations
114
+ OPERATIONS
115
+ end
116
+
117
+ define_method('app') do |**params|
118
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
119
+ request('googleplay-app', params, response_type: response_type)
120
+ end
121
+ define_method('categories') do |**params|
122
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
123
+ request('googleplay-categories', params, response_type: response_type)
124
+ end
125
+ define_method('datasafety') do |**params|
126
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
127
+ request('googleplay-datasafety', params, response_type: response_type)
128
+ end
129
+ define_method('developer') do |**params|
130
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
131
+ request('googleplay-developer', params, response_type: response_type)
132
+ end
133
+ define_method('list') do |**params|
134
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
135
+ request('googleplay-list', params, response_type: response_type)
136
+ end
137
+ define_method('permissions') do |**params|
138
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
139
+ request('googleplay-permissions', params, response_type: response_type)
140
+ end
141
+ define_method('ratings') do |**params|
142
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
143
+ request('googleplay-ratings', params, response_type: response_type)
144
+ end
145
+ define_method('reviews') do |**params|
146
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
147
+ request('googleplay-reviews', params, response_type: response_type)
148
+ end
149
+ define_method('search') do |**params|
150
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
151
+ request('googleplay-search', params, response_type: response_type)
152
+ end
153
+ define_method('similar') do |**params|
154
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
155
+ request('googleplay-similar', params, response_type: response_type)
156
+ end
157
+ define_method('suggest') do |**params|
158
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
159
+ request('googleplay-suggest', params, response_type: response_type)
160
+ end
161
+
162
+ private
163
+
164
+ # POST operations take their JSON body under the body parameter name or "body".
165
+ def request_body(operation, params)
166
+ name = operation["bodyParam"]
167
+ return nil if name.nil?
168
+ value = params.key?(name) ? params[name] : params["body"]
169
+ if value.nil?
170
+ raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
171
+ return nil
172
+ end
173
+ value.is_a?(String) ? value : JSON.generate(value)
174
+ end
175
+
176
+ def build_url(operation, params)
177
+ known = operation["params"].map { |param| param["name"] }
178
+ known << "body" if operation["bodyParam"]
179
+ unknown = params.keys - known
180
+ raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
181
+ path = operation["path"].dup
182
+ operation["params"].select { |param| param["in"] == "path" }.each do |param|
183
+ value = params[param["name"]]
184
+ raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
185
+ path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
186
+ end
187
+ pairs = []
188
+ operation["queryParams"].each do |param|
189
+ name = param["name"]
190
+ value = params.key?(name) ? params[name] : param["default"]
191
+ if value.nil?
192
+ raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
193
+ next
194
+ end
195
+ enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
196
+ if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
197
+ raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
198
+ end
199
+ if value.is_a?(Array)
200
+ format = param["collectionFormat"] || "csv"
201
+ if format == "multi"
202
+ value.each { |item| pairs << [name, scalar(item)] }
203
+ else
204
+ separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
205
+ pairs << [name, value.map { |item| scalar(item) }.join(separator)]
206
+ end
207
+ else
208
+ pairs << [name, scalar(value)]
209
+ end
210
+ end
211
+ query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
212
+ @base_url + path + (query.empty? ? "" : "?" + query)
213
+ end
214
+
215
+ def scalar(value)
216
+ value == true ? "true" : (value == false ? "false" : value.to_s)
217
+ end
218
+
219
+ def percent_encode(value)
220
+ URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
221
+ end
222
+
223
+ def parse_response(body, content_type, operation, params, response_type)
224
+ type = response_type.to_s
225
+ raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
226
+ format = operation["params"].find { |param| param["name"] == "format" }
227
+ text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
228
+ raw_format = params["format"] && text_formats.include?(params["format"].to_s)
229
+ json_format = format && format["enum"] && format["enum"].any? { |value| %w[json application/json].include?(value.to_s.downcase) } && %w[json application/json].include?(params["format"].to_s.downcase)
230
+ is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
231
+ return body if type == "text" || raw_format || (type == "auto" && !is_json)
232
+ JSON.parse(body)
233
+ rescue JSON::ParserError => error
234
+ raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
235
+ end
236
+
237
+ public
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,5 @@
1
+ module Crawlora
2
+ module Googleplay
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "googleplay/version"
2
+ require_relative "googleplay/client"
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crawlora-googleplay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Crawlora
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-10-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Credential-free Google Play API access through Crawlora's hosted service.
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - CHANGELOG.md
20
+ - LICENSE
21
+ - README.md
22
+ - lib/crawlora/googleplay.rb
23
+ - lib/crawlora/googleplay/client.rb
24
+ - lib/crawlora/googleplay/version.rb
25
+ homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=googleplay-ruby-homepage
26
+ licenses:
27
+ - MIT
28
+ metadata:
29
+ source_code_uri: https://github.com/Crawlora-org/crawlora-googleplay
30
+ documentation_uri: https://github.com/Crawlora-org/crawlora-googleplay/blob/main/ruby/README.md
31
+ rubygems_mfa_required: 'true'
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.4.19
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Google Play client for the Crawlora hosted API
51
+ test_files: []