opera-mobile-store-sdk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +39 -0
  9. data/Rakefile +2 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/lib/opera-mobile-store-sdk.rb +69 -0
  13. data/lib/opera-mobile-store-sdk/version.rb +5 -0
  14. data/lib/opera/mobile_store/author.rb +31 -0
  15. data/lib/opera/mobile_store/build.rb +88 -0
  16. data/lib/opera/mobile_store/build_file.rb +27 -0
  17. data/lib/opera/mobile_store/category.rb +31 -0
  18. data/lib/opera/mobile_store/developer.rb +70 -0
  19. data/lib/opera/mobile_store/payment_info.rb +105 -0
  20. data/lib/opera/mobile_store/product.rb +157 -0
  21. data/lib/opera/mobile_store/product_image.rb +42 -0
  22. data/lib/opera/mobile_store/product_localization.rb +35 -0
  23. data/lib/opera/mobile_store_sdk/api_accessible.rb +44 -0
  24. data/lib/opera/mobile_store_sdk/api_object_list.rb +174 -0
  25. data/lib/opera/mobile_store_sdk/config.rb +71 -0
  26. data/lib/opera/mobile_store_sdk/errors.rb +10 -0
  27. data/lib/opera/mobile_store_sdk/faraday_middleware.rb +4 -0
  28. data/lib/opera/mobile_store_sdk/faraday_middleware/authentication.rb +76 -0
  29. data/lib/opera/mobile_store_sdk/faraday_middleware/required_response_format.rb +14 -0
  30. data/lib/opera/mobile_store_sdk/faraday_middleware/response_parser.rb +45 -0
  31. data/lib/opera/mobile_store_sdk/faraday_middleware/sdk_benchmark.rb +47 -0
  32. data/lib/opera/mobile_store_sdk/identity_mapable.rb +35 -0
  33. data/opera-mobile-store-sdk.gemspec +35 -0
  34. metadata +174 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ef23d96109139c5a09b57d6fb5e31bcc35baf6d
4
+ data.tar.gz: ee58fda10f20bc9895b7e9eea0d30209e4267ab6
5
+ SHA512:
6
+ metadata.gz: 983993cc0dd055f20366267a5b2ba093e8ae78e89bc7599f3f749a25e7eeca4a25006f33c88a35d71ea1cdcfa8b1caa0f000317a5d75cb536ace0e9a8b73e27e
7
+ data.tar.gz: e627c31ccb5af62e9fe5a29217d379fc558d1176e3ad3e02bf4e2ebe374180ebab26bb660a9d01d5f3e5a465494d68112ae505d2e00b9ef5d8d3907f0a2e72af
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in opera-mobile-store-sdk.gemspec
4
+ gemspec
5
+
6
+
7
+ gem "byebug"
8
+ gem "pry"
9
+ gem "patron"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Roberto Quintanilla
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Opera::Mobile::Store::Sdk
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/opera/mobile/store/sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'opera-mobile-store-sdk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install opera-mobile-store-sdk
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/opera-mobile-store-sdk/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "opera/mobile/store/sdk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,69 @@
1
+ require "opera-mobile-store-sdk/version"
2
+ require 'active_support/all'
3
+
4
+ module Opera
5
+
6
+ module MobileStore
7
+ extend ActiveSupport::Autoload
8
+ autoload :Product
9
+ autoload :ProductLocalization
10
+ autoload :ProductImage
11
+ autoload :Category
12
+ autoload :Author
13
+ autoload :Build
14
+ autoload :BuildFile
15
+ autoload :Developer
16
+ autoload :PaymentInfo
17
+ end
18
+
19
+ module MobileStoreSDK
20
+ extend ActiveSupport::Autoload
21
+
22
+ autoload :APIAccessible
23
+ autoload :APIObjectList
24
+ autoload :Config
25
+ autoload :Errors
26
+ autoload :IdentityMapable
27
+
28
+ def self.config
29
+ @config ||= Opera::MobileStoreSDK::Config.new
30
+ end
31
+
32
+ def self.logger
33
+ config.logger
34
+ end
35
+
36
+ def self.html_entities
37
+ @html_entities ||= begin
38
+ require 'htmlentities'
39
+ HTMLEntities.new
40
+ end
41
+ end
42
+
43
+ def self.connection
44
+ @connection ||= Faraday.new(url: Opera::MobileStoreSDK.config.api_host) do |faraday|
45
+
46
+ # faraday.response :logger # log requests to STDOUT
47
+
48
+ faraday.use MobileStoreSDK::FaradayMiddleware::RequiredResponseFormat
49
+
50
+ faraday.use MobileStoreSDK::FaradayMiddleware::Authentication,
51
+ MobileStoreSDK.config.username,
52
+ MobileStoreSDK.config.password,
53
+ authentication: MobileStoreSDK.config.authentication
54
+
55
+ faraday.use MobileStoreSDK::FaradayMiddleware::ResponseParser
56
+
57
+ faraday.use MobileStoreSDK::FaradayMiddleware::SDKBenchmark
58
+
59
+ if defined?(Patron)
60
+ faraday.adapter :patron
61
+ else
62
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,5 @@
1
+ module Opera
2
+ module MobileStoreSDK
3
+ VERSION = "0.1.0" #
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ module Opera
2
+ module MobileStore
3
+ class Author
4
+
5
+ include ActiveModel::Model
6
+
7
+ include Opera::MobileStoreSDK::IdentityMapable
8
+
9
+ # All attributes are Read-Only...
10
+ attr_accessor :id, :name, :email
11
+
12
+ def attributes
13
+ [:id, :name, :email].inject({}) do |hash, method|
14
+ value = self.public_send method
15
+ hash[method] = value unless value.nil?
16
+ hash
17
+ end
18
+ end
19
+
20
+ def inspect
21
+ attr_inspect = attributes.inject [] do |attributes, keyval|
22
+ key, val = keyval
23
+ attributes + ["#{key}:#{val}"]
24
+ end.join(", ")
25
+
26
+ "<#{self.class.name} #{attr_inspect}>"
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,88 @@
1
+ module Opera
2
+ module MobileStore
3
+ class Build
4
+
5
+ include ActiveModel::Model
6
+
7
+ # include Opera::MobileStoreSDK::IdentityMapable
8
+
9
+ # All attributes are Read-Only...
10
+ attr_accessor :id,
11
+ :name,
12
+ :platform,
13
+ :type,
14
+ :installer_type,
15
+ :package_name,
16
+ :version_name,
17
+ :version_code,
18
+ :build_update_date,
19
+ :files,
20
+ :billing,
21
+ :languages
22
+
23
+ def files
24
+ @files ||= []
25
+ end
26
+
27
+ def languages
28
+ @languages ||= []
29
+ end
30
+
31
+ def billing
32
+ @billing ||= false
33
+ end
34
+
35
+ def self.build_from_nokogiri_node(node)
36
+
37
+ version_code = node.xpath("string(version_code)")
38
+
39
+ data = {
40
+ id: node.xpath("string(@id)").to_i,
41
+ name: node.xpath("string(name)").strip,
42
+ platform: node.xpath("string(platform)").strip,
43
+ type: node.xpath("string(type)").strip,
44
+ installer_type: node.xpath("string(installer_type)").strip,
45
+ package_name: node.xpath("string(package_name)").strip,
46
+ version_name: node.xpath("string(version_name)").strip,
47
+ version_code: version_code.present? ? version_code.to_i : nil,
48
+ build_update_date: Time.parse(node.xpath "string(build_update_date)"),
49
+ }.select { |key, val| val.present? }
50
+
51
+ data[:files] = node.xpath("files/file").map do |f|
52
+ BuildFile.build_from_nokogiri_node f
53
+ end
54
+
55
+ data[:billing] = node.xpath("string(billing)").to_i > 0
56
+
57
+ data[:languages] = node.xpath("languages/language").map do |language|
58
+ language.attributes["code"].to_s.strip
59
+ end
60
+
61
+ self.new data
62
+ end
63
+
64
+ def attributes
65
+ [
66
+ :id, :name, :platform, :type, :installer_type, :package_name,
67
+ :version_name, :version_code, :build_update_date, :files, :billing,
68
+ :languages
69
+ ].inject({}) do |hash, method|
70
+ value = self.public_send method
71
+ hash[method] = value unless value.nil?
72
+ hash
73
+ end
74
+ end
75
+
76
+ def inspect
77
+ attr_inspect = attributes.inject [] do |attributes, keyval|
78
+ key, val = keyval
79
+ attributes + ["#{key}:#{val}"]
80
+ end.join(", ")
81
+
82
+ "<#{self.class.name} #{attr_inspect}>"
83
+ end
84
+
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,27 @@
1
+ module Opera
2
+ module MobileStore
3
+ class BuildFile
4
+
5
+ include ActiveModel::Model
6
+
7
+ # All attributes are Read-Only...
8
+ attr_accessor :size, :url
9
+
10
+ def self.build_from_nokogiri_node(node)
11
+
12
+ data = { url: node.text.strip }
13
+
14
+ # Extract width + height data:
15
+ file_size = node.xpath("string(@size)")
16
+ data[:size] = file_size.to_i if file_size.present?
17
+
18
+ self.new data
19
+ end
20
+
21
+ def inspect
22
+ "<#{self.class.name} size:#{size}, url:#{url}>"
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ module Opera
2
+ module MobileStore
3
+ class Category
4
+
5
+ include ActiveModel::Model
6
+
7
+ include Opera::MobileStoreSDK::IdentityMapable
8
+
9
+ # All attributes are Read-Only...
10
+ attr_accessor :id, :code, :name
11
+
12
+ def attributes
13
+ [:id, :code, :name].inject({}) do |hash, method|
14
+ value = self.public_send method
15
+ hash[method] = value unless value.nil?
16
+ hash
17
+ end
18
+ end
19
+
20
+ def inspect
21
+ attr_inspect = attributes.inject [] do |attributes, keyval|
22
+ key, val = keyval
23
+ attributes + ["#{key}:#{val}"]
24
+ end.join(", ")
25
+
26
+ "<#{self.class.name} #{attr_inspect}>"
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,70 @@
1
+ require "active_model"
2
+
3
+ module Opera
4
+ module MobileStore
5
+ class Developer
6
+
7
+ include ActiveModel::Model
8
+
9
+ include Opera::MobileStoreSDK::APIAccessible
10
+
11
+ # All attributes are Read-Only...
12
+ attr_accessor :id, :login, :email, :name,
13
+ :address1, :address2,
14
+ :city, :state, :zip, :country_code, :website_url,
15
+ :orders_email, :contact_email, :payment_info
16
+
17
+ def self.build_from_nokogiri_node(node)
18
+
19
+ data = { id: node.xpath("string(@id)").to_i }
20
+
21
+ login = node.xpath("string(@login)").strip
22
+ data[:login] = login if login.present?
23
+
24
+ data[:email] = node.xpath("string(email)").strip
25
+ data[:name] = node.xpath("string(name)").strip
26
+
27
+ data[:address1] = node.xpath("string(address1)").strip
28
+ data[:address2] = node.xpath("string(address2)").strip
29
+
30
+ [
31
+ :city, :state, :zip, :country_code, :website_url,
32
+ :orders_email, :contact_email
33
+ ].each do |attribute_name|
34
+ value = node.xpath("string(#{attribute_name})").strip
35
+ data[attribute_name] = value if value.present?
36
+ end
37
+
38
+ phones = node.xpath("phones").text
39
+ byebug if phones.present?
40
+
41
+ payment_info = PaymentInfo.build_from_nokogiri_node node.xpath("payment").first
42
+ data[:payment_info] = payment_info if payment_info.present?
43
+
44
+
45
+ self.new data
46
+ end
47
+
48
+ def attributes
49
+ [
50
+ :id, :login, :email, :name, :address1, :address2, :city, :state, :zip,
51
+ :country_code, :website_url, :orders_email, :contact_email, :payment_info
52
+ ].inject({}) do |hash, method|
53
+ value = public_send method
54
+ hash[method] = value if value.present?
55
+ hash
56
+ end
57
+ end
58
+
59
+ def inspect
60
+ attr_inspect = attributes.inject [] do |attributes, keyval|
61
+ key, val = keyval
62
+ attributes + ["#{key}:#{val}"]
63
+ end.join(", ")
64
+
65
+ "<#{self.class.name} #{attr_inspect}>"
66
+ end
67
+
68
+ end
69
+ end
70
+ end