brickset_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +145 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/brickset.gemspec +30 -0
  13. data/lib/brickset.rb +55 -0
  14. data/lib/brickset/api/auth.rb +22 -0
  15. data/lib/brickset/api/collection/advanced.rb +34 -0
  16. data/lib/brickset/api/collection/minifig.rb +35 -0
  17. data/lib/brickset/api/collection/set.rb +117 -0
  18. data/lib/brickset/api/set.rb +157 -0
  19. data/lib/brickset/client.rb +56 -0
  20. data/lib/brickset/configuration.rb +9 -0
  21. data/lib/brickset/elements/additional_image.rb +13 -0
  22. data/lib/brickset/elements/collection_detail.rb +28 -0
  23. data/lib/brickset/elements/collection_total.rb +15 -0
  24. data/lib/brickset/elements/condition.rb +11 -0
  25. data/lib/brickset/elements/instruction.rb +12 -0
  26. data/lib/brickset/elements/minifig_collection.rb +15 -0
  27. data/lib/brickset/elements/review.rb +20 -0
  28. data/lib/brickset/elements/set.rb +67 -0
  29. data/lib/brickset/elements/subtheme.rb +15 -0
  30. data/lib/brickset/elements/theme.rb +15 -0
  31. data/lib/brickset/elements/user_note.rb +12 -0
  32. data/lib/brickset/elements/year.rb +13 -0
  33. data/lib/brickset/version.rb +3 -0
  34. data/spec/brickset/api/auth_spec.rb +84 -0
  35. data/spec/brickset/api/collection/advanced_spec.rb +59 -0
  36. data/spec/brickset/api/collection/minifig_spec.rb +95 -0
  37. data/spec/brickset/api/collection/set_spec.rb +350 -0
  38. data/spec/brickset/api/set_spec.rb +658 -0
  39. data/spec/brickset/client_spec.rb +155 -0
  40. data/spec/brickset/configuration_spec.rb +9 -0
  41. data/spec/brickset/elements/additional_image_spec.rb +26 -0
  42. data/spec/brickset/elements/collection_detail_spec.rb +40 -0
  43. data/spec/brickset/elements/collection_total_spec.rb +27 -0
  44. data/spec/brickset/elements/condition_spec.rb +23 -0
  45. data/spec/brickset/elements/instruction_spec.rb +24 -0
  46. data/spec/brickset/elements/minifig_collection_spec.rb +27 -0
  47. data/spec/brickset/elements/review_spec.rb +32 -0
  48. data/spec/brickset/elements/set_spec.rb +72 -0
  49. data/spec/brickset/elements/subtheme_spec.rb +27 -0
  50. data/spec/brickset/elements/theme_spec.rb +27 -0
  51. data/spec/brickset/elements/user_note_spec.rb +24 -0
  52. data/spec/brickset/elements/year_spec.rb +25 -0
  53. data/spec/brickset_spec.rb +59 -0
  54. data/spec/fixtures/api_key_invalid.xml +2 -0
  55. data/spec/fixtures/api_key_valid.xml +2 -0
  56. data/spec/fixtures/get_additional_images.xml +24 -0
  57. data/spec/fixtures/get_additional_images_no_result.xml +2 -0
  58. data/spec/fixtures/get_collection_detail.xml +23 -0
  59. data/spec/fixtures/get_collection_detail_conditions.xml +24 -0
  60. data/spec/fixtures/get_collection_detail_no_result.xml +2 -0
  61. data/spec/fixtures/get_collection_totals.xml +8 -0
  62. data/spec/fixtures/get_collection_totals_no_result.xml +8 -0
  63. data/spec/fixtures/get_instructions.xml +7 -0
  64. data/spec/fixtures/get_instructions_no_result.xml +2 -0
  65. data/spec/fixtures/get_minifig_collection.xml +31 -0
  66. data/spec/fixtures/get_minifig_collection_owned.xml +17 -0
  67. data/spec/fixtures/get_minifig_collection_wanted.xml +10 -0
  68. data/spec/fixtures/get_recently_updated_sets.xml +52 -0
  69. data/spec/fixtures/get_recently_updated_sets_invalid_key.xml +1 -0
  70. data/spec/fixtures/get_reviews.xml +28 -0
  71. data/spec/fixtures/get_reviews_no_result.xml +2 -0
  72. data/spec/fixtures/get_set.xml +52 -0
  73. data/spec/fixtures/get_set_no_result.xml +2 -0
  74. data/spec/fixtures/get_sets.xml +101 -0
  75. data/spec/fixtures/get_sets_no_result.xml +2 -0
  76. data/spec/fixtures/get_subthemes.xml +24 -0
  77. data/spec/fixtures/get_subthemes_for_user.xml +24 -0
  78. data/spec/fixtures/get_subthemes_for_user_no_result.xml +2 -0
  79. data/spec/fixtures/get_subthemes_for_user_owned.xml +24 -0
  80. data/spec/fixtures/get_subthemes_for_user_wanted.xml +31 -0
  81. data/spec/fixtures/get_subthemes_no_result.xml +2 -0
  82. data/spec/fixtures/get_themes.xml +17 -0
  83. data/spec/fixtures/get_themes_for_user.xml +17 -0
  84. data/spec/fixtures/get_themes_for_user_no_result.xml +2 -0
  85. data/spec/fixtures/get_themes_for_user_owned.xml +17 -0
  86. data/spec/fixtures/get_themes_for_user_wanted.xml +25 -0
  87. data/spec/fixtures/get_themes_no_result.xml +2 -0
  88. data/spec/fixtures/get_user_notes.xml +11 -0
  89. data/spec/fixtures/get_user_notes_no_result.xml +2 -0
  90. data/spec/fixtures/get_years.xml +18 -0
  91. data/spec/fixtures/get_years_for_user.xml +18 -0
  92. data/spec/fixtures/get_years_for_user_no_result.xml +2 -0
  93. data/spec/fixtures/get_years_for_user_owned.xml +13 -0
  94. data/spec/fixtures/get_years_for_user_wanted.xml +13 -0
  95. data/spec/fixtures/get_years_no_result.xml +2 -0
  96. data/spec/fixtures/login.xml +2 -0
  97. data/spec/fixtures/login_invalid_credentials.xml +2 -0
  98. data/spec/fixtures/login_invalid_key.xml +2 -0
  99. data/spec/fixtures/set_collection.xml +2 -0
  100. data/spec/fixtures/set_collection_invalid.xml +2 -0
  101. data/spec/fixtures/set_collection_owns.xml +2 -0
  102. data/spec/fixtures/set_collection_owns_invalid.xml +2 -0
  103. data/spec/fixtures/set_collection_qty_owned.xml +2 -0
  104. data/spec/fixtures/set_collection_qty_owned_invalid.xml +2 -0
  105. data/spec/fixtures/set_collection_user_notes.xml +2 -0
  106. data/spec/fixtures/set_collection_user_notes_invalid.xml +2 -0
  107. data/spec/fixtures/set_collection_wants.xml +2 -0
  108. data/spec/fixtures/set_collection_wants_invalid.xml +2 -0
  109. data/spec/fixtures/set_minifig_collection.xml +2 -0
  110. data/spec/fixtures/set_minifig_collection_invalid.xml +2 -0
  111. data/spec/fixtures/set_user_rating.xml +2 -0
  112. data/spec/fixtures/set_user_rating_invalid.xml +2 -0
  113. data/spec/fixtures/token_invalid.xml +2 -0
  114. data/spec/fixtures/token_valid.xml +2 -0
  115. data/spec/spec_helper.rb +43 -0
  116. metadata +355 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6b52a875ab697e5d7236fd7be4ff598d51af251db24f15ea5ce0545f1632784
4
+ data.tar.gz: cb26e22a5969958241a87c8296371fc11efa2a1210c618d172638a698692474f
5
+ SHA512:
6
+ metadata.gz: 7ae116a2f2fd9d6bdd25d3c1839dc89511cdc8736f4f67ca8871632cba3a3f64c3d2a01ea1209fc2334ad8231a3dd9d57f4525c228558f2ca20fe0fd40aab7b2
7
+ data.tar.gz: 11339bb1026597277aef1b0280042d749692b32dae6765292b6169e9afae512edde14514f3604065b6efe5a464a18ac8b0657fe9ed0701bc8c23214b580bb011
@@ -0,0 +1,11 @@
1
+ .DS_Store
2
+ .rspec
3
+ .rspec_status
4
+ .config
5
+ .bundle
6
+ *.gem
7
+ Gemfile.lock
8
+ doc/
9
+ pkg/*
10
+ docker
11
+ coverage
@@ -0,0 +1 @@
1
+ brickset
@@ -0,0 +1 @@
1
+ ruby-2.5.1
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ script: rspec
3
+ rvm:
4
+ - 2.5.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in brickset_api.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Kevin Tuhumury
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,145 @@
1
+ # Brickset
2
+
3
+ [![Build Status](https://travis-ci.org/kevintuhumury/brickset.png?branch=master)](https://travis-ci.org/kevintuhumury/brickset)
4
+
5
+ This gem provides a Ruby wrapper around the [Brickset](https://brickset.com) (v2) API, using HTTParty. Brickset is a library to access the Brickset API in an easy way. It wraps all of the methods, which are described in the [official documentation](https://brickset.com/tools/webservices/v2). The Brickset API by default responds with XML. This gem maps the XML responses to Ruby objects using HappyMapper.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'brickset_api', require: 'brickset'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install brickset_api
22
+
23
+ ### Apply for an API key
24
+
25
+ You can retrieve an API key from the official Brickset [site](https://brickset.com/tools/webservices/requestkey). Just follow the instructions and once you've received the API key move on to the next step.
26
+
27
+ ### Configuration
28
+
29
+ In order for you to use the Brickset gem, you'll need to configure the API key you've requested in the previous step. If you're using Rails, you could add the following to e.g. `config/initializers/brickset.rb`:
30
+
31
+ ```ruby
32
+ Brickset.configure do |config|
33
+ config.api_key = '<API_KEY>'
34
+ end
35
+ ```
36
+
37
+ That's it. You're now ready to start using this gem.
38
+
39
+ ## Usage
40
+
41
+ Using Brickset is easy. All you need to know is that all calls go through the `Brickset::Client` class. Most of the API calls provided by the Brickset v2 API require you to sign into Brickset in order for you to retrieve a token (which they call a `userHash`). This `token` can than be used to call the authenticated API calls and retrieve information of the signed in user.
42
+
43
+ Now, you're not required to do so, but if you don't, you will only be able to retrieve generic information from the API. User specific information will not be accessible.
44
+
45
+ ### Create an instance of the Brickset client
46
+
47
+ In order to retrieve data from the API, we'll need an instance of the Brickset client. So let's create it:
48
+
49
+ ```ruby
50
+ client = Brickset.client
51
+ ```
52
+
53
+ Yeah, that's it.
54
+
55
+ ### Create an instance of the Brickset client with access to authenticated API calls
56
+
57
+ If you want to retrieve user specific information you'll need a token. You can retrieve one as follows:
58
+
59
+ ```ruby
60
+ token = Brickset.login('<YOUR_USERNAME>', '<YOUR_PASSWORD>')
61
+ ```
62
+
63
+ Now that you have access to the token, provide the client with it and you'll be good to go:
64
+
65
+ ```ruby
66
+ client = Brickset.client(token: token)
67
+ ```
68
+
69
+ That's it.
70
+
71
+ ### Helper methods
72
+
73
+ There are two helper methods that you can use to check whether your API key and token are valid. Both of them will return a Boolean value. You can use them as follows:
74
+
75
+ ```ruby
76
+ client.valid_api_key? # => true
77
+ client.valid_token? # => true
78
+ ```
79
+
80
+ ### Calling API methods
81
+
82
+ Now, let's call our `sets` method with `Star Wars` (because its awesome, obviously) as a theme:
83
+
84
+ ```ruby
85
+ sets = client.sets(theme: 'Star Wars')
86
+ ```
87
+
88
+ The above call will return all sets that are in the `Star Wars` theme. As can be seen on the [API page](https://brickset.com/tools/webservices/v2) (look for `getSets`), there's a default limit of 20 records per page to retrieve. You could change that with the following:
89
+
90
+ ```ruby
91
+ sets = client.sets(theme: 'Star Wars', page_size: 50)
92
+ ```
93
+
94
+ Or navigate to the second page:
95
+
96
+ ```ruby
97
+ sets = client.sets(theme: 'Star Wars', page_number: 2)
98
+ ```
99
+
100
+ Let's say you're looking for the `Ultimate Collector Series` sets and more specifically the ones based on the `Millenium Falcon`. You can retrieve those with the following example:
101
+
102
+ ```ruby
103
+ sets = client.sets(theme: 'Star Wars', subtheme: 'Ultimate Collector Series', query: 'Millenium Falcon')
104
+ ```
105
+
106
+ At the time of writing this will result in two sets: `10179-1` from 2007 and `75192-1` from 2017. Let's say we want to select the last one to view its data:
107
+
108
+ ```ruby
109
+ sets = client.sets(theme: 'Star Wars', subtheme: 'Ultimate Collector Series', query: 'Millenium Falcon')
110
+ set = sets.last # => #<Brickset::Elements::Set:0x000055ad9ddfdd60 @set_id=26725, @number="75192", @number_variant=1, @name="Millennium Falcon", @year="2017", @description=nil, @category="Normal", @theme="Star Wars", @theme_group="Licensed", @subtheme="Ultimate Collector Series", @pieces="7541", @minifigs="8", @image=true, @image_url="https://images.brickset.com/sets/images/75192-1.jpg", @image_filename="75192-1", @thumbnail_url="https://images.brickset.com/sets/thumbs/tn_75192-1_jpg.jpg", @thumbnail_url_large="https://images.brickset.com/sets/small/75192-1.jpg", @brickset_url="https://brickset.com/sets/75192-1", @owned_by_total=5194, @wanted_by_total=4551, @released=true, @rating=5.0, @user_rating=4, @review_count=3, @instructions_count=2, @additional_image_count=61, @last_updated=Thu, 14 Sep 2017, @age_minimum=16, @age_maximum=nil, @notes=nil, @tags=nil, @retail_price_uk="649.99", @retail_price_us="799.99", @retail_price_ca="899.99", @retail_price_eu="799.99", @date_added_to_shop="2018-01-10", @date_removed_from_shop="", @packaging_type="Box", @height=0.0, @width=0.0, @depth=0.0, @weight=0.0, @availability="LEGO exclusive", @ean="", @upc="", @acm_data_count=0, @owned=true, @wanted=true, @number_owned=1, @user_notes="">
111
+
112
+ set.id # => 26725
113
+ set.pieces # => '7541'
114
+ set.image_url # => 'https://images.brickset.com/sets/images/75192-1.jpg'
115
+ set.additional_image_count # => 61
116
+ ```
117
+
118
+ You could now use `additional_images` to retrieve the 61 additional images from the above set. Simply supply the API call with the set ID:
119
+
120
+ ```ruby
121
+ client.additional_images(set.id)
122
+
123
+ # => [#<Brickset::Elements::AdditionalImage:0x000055ad9e0292b0 @thumbnail_url="https://images.brickset.com/sets/AdditionalImages/75192-1/tn_75192_1to1_jpg.jpg", @thumbnail_url_large=nil, @image_url="https://images.brickset.com/sets/AdditionalImages/75192-1/75192_1to1.jpg">, #<Brickset::Elements::AdditionalImage:0x000055ad9e027d98 @thumbnail_url="https://images.brickset.com/sets/AdditionalImages/75192-1/tn_75192_alt10_jpg.jpg", @thumbnail_url_large=nil, @image_url="https://images.brickset.com/sets/AdditionalImages/75192-1/75192_alt10.jpg">, ...]
124
+ ```
125
+
126
+ It really is that easy. Need a specific method? Look for them in the `lib/brickset/api` directory.
127
+
128
+ ## Contributing
129
+
130
+ You're very welcome to contribute to this gem. To do so, please follow these steps:
131
+
132
+ 1. Fork this project
133
+ 2. Clone your fork on your local machine
134
+ 3. Install the development dependencies with `bin/setup`
135
+ 4. Create your feature branch with `git checkout -b my-new-feature`
136
+ 5. Run the specs with `bundle exec rspec` and make sure everything is covered with RSpec
137
+ 6. Commit your changes `git commit -am 'Added new feature'`
138
+ 7. Push to your branch `git push origin my-new-feature`
139
+ 8. Create a new Pull Request
140
+
141
+ You can run `bin/console` for an interactive prompt that will allow you to experiment.
142
+
143
+ ## Copyright
144
+
145
+ Copyright 2018 Kevin Tuhumury. Released under the MIT License.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'brickset'
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'brickset/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'brickset_api'
7
+ spec.version = Brickset::VERSION
8
+ spec.authors = ['Kevin Tuhumury']
9
+ spec.email = ['kevin.tuhumury@gmail.com']
10
+
11
+ spec.summary = %q{A Ruby wrapper around the Brickset.com (v2) API.}
12
+ spec.description = %q{This gem provides a Ruby wrapper around the Brickset.com (v2) API. The Brickset.com API responds with XML. This gem maps that into Ruby objects using Happymapper.}
13
+ spec.homepage = 'https://github.com/kevintuhumury/brickset_api'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'httparty', '~> 0.16'
22
+ spec.add_runtime_dependency 'nokogiri-happymapper', '~> 0.8'
23
+ spec.add_runtime_dependency 'activemodel', '>= 5.2'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'webmock', '~> 3.4'
29
+ spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
30
+ end
@@ -0,0 +1,55 @@
1
+ require 'httparty'
2
+ require 'happymapper'
3
+ require 'active_model'
4
+ require 'active_support/all'
5
+
6
+ require 'brickset/version'
7
+ require 'brickset/configuration'
8
+
9
+ require 'brickset/elements/set'
10
+ require 'brickset/elements/year'
11
+ require 'brickset/elements/theme'
12
+ require 'brickset/elements/subtheme'
13
+ require 'brickset/elements/instruction'
14
+ require 'brickset/elements/additional_image'
15
+ require 'brickset/elements/review'
16
+ require 'brickset/elements/collection_detail'
17
+ require 'brickset/elements/collection_total'
18
+ require 'brickset/elements/minifig_collection'
19
+ require 'brickset/elements/user_note'
20
+ require 'brickset/elements/condition'
21
+
22
+ require 'brickset/api/auth'
23
+ require 'brickset/api/set'
24
+ require 'brickset/api/collection/set'
25
+ require 'brickset/api/collection/minifig'
26
+ require 'brickset/api/collection/advanced'
27
+
28
+ module Brickset
29
+ ValidationError = Class.new(StandardError)
30
+
31
+ BASE_URI = 'https://brickset.com/api/v2.asmx'.freeze
32
+
33
+ class << self
34
+ attr_accessor :configuration
35
+
36
+ def client(options = {})
37
+ Brickset::Client.new(options)
38
+ end
39
+
40
+ def login(username, password)
41
+ client.login(username, password)
42
+ end
43
+
44
+ def configure
45
+ self.configuration ||= Configuration.new
46
+ yield(configuration)
47
+ end
48
+
49
+ def reset
50
+ self.configuration = Configuration.new
51
+ end
52
+ end
53
+ end
54
+
55
+ require 'brickset/client'
@@ -0,0 +1,22 @@
1
+ module Brickset
2
+ module Api
3
+ module Auth
4
+
5
+ def login(username, password)
6
+ xml = call('/login', username: username, password: password)
7
+ HappyMapper.parse(xml).content
8
+ end
9
+
10
+ def valid_api_key?
11
+ xml = call('/checkKey')
12
+ HappyMapper.parse(xml).content == 'OK'
13
+ end
14
+
15
+ def valid_token?
16
+ xml = call('/checkUserHash')
17
+ HappyMapper.parse(xml).content != 'INVALID'
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Brickset
2
+ module Api
3
+ module Collection
4
+ module Advanced
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_accessor :condition
9
+
10
+ with_options(on: :collection_detail_conditions) do |options|
11
+ options.validates :condition, inclusion: { in: %w(acquired now) }
12
+ end
13
+ end
14
+
15
+ def collection_detail(set_id)
16
+ xml = call('/getCollectionDetail', setID: set_id)
17
+ Brickset::Elements::CollectionDetail.parse(xml, single: true)
18
+ end
19
+
20
+ def collection_detail_conditions(condition)
21
+ self.condition = condition
22
+
23
+ if valid?(:collection_detail_conditions)
24
+ xml = call('/getCollectionDetailConditions', which: condition)
25
+ Brickset::Elements::Condition.parse(xml)
26
+ else
27
+ raise ValidationError, self.errors.full_messages.to_sentence
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ module Brickset
2
+ module Api
3
+ module Collection
4
+ module Minifig
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_accessor :minifig_number, :number_owned, :wanted
9
+
10
+ with_options(on: :update_minifig_collection) do |options|
11
+ options.validates :minifig_number, :number_owned, :wanted, presence: true
12
+ options.validates :number_owned, inclusion: { in: (0..999) }
13
+ options.validates :wanted, inclusion: { in: [0, 1] }
14
+ end
15
+ end
16
+
17
+ def minifig_collection(query: '', owned: '', wanted: '')
18
+ xml = call('/getMinifigCollection', query: query, owned: owned, wanted: wanted)
19
+ Brickset::Elements::MinifigCollection.parse xml
20
+ end
21
+
22
+ def update_minifig_collection(options)
23
+ extract_attributes_from_options(options)
24
+
25
+ if valid?(:update_minifig_collection)
26
+ handle_update call('/setMinifigCollection', minifigNumber: minifig_number, qtyOwned: number_owned, wanted: wanted)
27
+ else
28
+ raise ValidationError, self.errors.full_messages.to_sentence
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,117 @@
1
+ module Brickset
2
+ module Api
3
+ module Collection
4
+ module Set
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_accessor :set_id, :number_owned, :wanted, :owned, :notes, :rating
9
+
10
+ with_options(on: :update_collection) do |options|
11
+ options.validates :set_id, :number_owned, :wanted, presence: true
12
+ options.validates :number_owned, inclusion: { in: (0..999) }
13
+ options.validates :wanted, inclusion: { in: [0, 1] }
14
+ end
15
+
16
+ with_options(on: :update_collection_owned) do |options|
17
+ options.validates :set_id, :owned, presence: true
18
+ options.validates :owned, inclusion: { in: [0, 1] }
19
+ end
20
+
21
+ with_options(on: :update_collection_wanted) do |options|
22
+ options.validates :set_id, :wanted, presence: true
23
+ options.validates :wanted, inclusion: { in: [0, 1] }
24
+ end
25
+
26
+ with_options(on: :update_collection_number_owned) do |options|
27
+ options.validates :set_id, :number_owned, presence: true
28
+ options.validates :number_owned, inclusion: { in: (0..999) }
29
+ end
30
+
31
+ with_options(on: :update_collection_user_notes) do |options|
32
+ options.validates :set_id, :notes, presence: true
33
+ options.validates :notes, length: { maximum: 200 }
34
+ end
35
+
36
+ with_options(on: :update_user_rating) do |options|
37
+ options.validates :set_id, :rating, presence: true
38
+ options.validates :rating, inclusion: { in: (0..5) }
39
+ end
40
+ end
41
+
42
+ def collection_totals
43
+ xml = call('/getCollectionTotals')
44
+ Brickset::Elements::CollectionTotal.parse(xml)
45
+ end
46
+
47
+ def update_collection(options)
48
+ extract_attributes_from_options(options)
49
+
50
+ if valid?(:update_collection)
51
+ handle_update call('/setCollection', setID: set_id, qtyOwned: number_owned, wanted: wanted)
52
+ else
53
+ raise ValidationError, self.errors.full_messages.to_sentence
54
+ end
55
+ end
56
+
57
+ def update_collection_owned(options)
58
+ extract_attributes_from_options(options)
59
+
60
+ if valid?(:update_collection_owned)
61
+ handle_update call('/setCollection_owns', setID: set_id, owned: owned)
62
+ else
63
+ raise ValidationError, self.errors.full_messages.to_sentence
64
+ end
65
+ end
66
+
67
+ def update_collection_wanted(options)
68
+ extract_attributes_from_options(options)
69
+
70
+ if valid?(:update_collection_wanted)
71
+ handle_update call('/setCollection_wants', setID: set_id, wanted: wanted)
72
+ else
73
+ raise ValidationError, self.errors.full_messages.to_sentence
74
+ end
75
+ end
76
+
77
+ def update_collection_number_owned(options)
78
+ extract_attributes_from_options(options)
79
+
80
+ if valid?(:update_collection_number_owned)
81
+ handle_update call('/setCollection_qtyOwned', setID: set_id, qtyOwned: number_owned)
82
+ else
83
+ raise ValidationError, self.errors.full_messages.to_sentence
84
+ end
85
+ end
86
+
87
+ def update_collection_user_notes(options)
88
+ extract_attributes_from_options(options)
89
+
90
+ if valid?(:update_collection_user_notes)
91
+ handle_update call('/setCollection_userNotes', setID: set_id, notes: notes)
92
+ else
93
+ raise ValidationError, self.errors.full_messages.to_sentence
94
+ end
95
+ end
96
+
97
+ def update_user_rating(options)
98
+ extract_attributes_from_options(options)
99
+
100
+ if valid?(:update_user_rating)
101
+ handle_update call('/setUserRating', setID: set_id, rating: rating)
102
+ else
103
+ raise ValidationError, self.errors.full_messages.to_sentence
104
+ end
105
+ end
106
+
107
+ def user_notes
108
+ xml = call('/getUserNotes')
109
+ Brickset::Elements::UserNote.parse(xml).reject do |user_note|
110
+ user_note.set_id.nil? && user_note.user_notes.nil?
111
+ end
112
+ end
113
+
114
+ end
115
+ end
116
+ end
117
+ end