brickset 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/brickset.gemspec +27 -0
- data/lib/brickset.rb +8 -0
- data/lib/brickset/client.rb +54 -0
- data/lib/brickset/configuration.rb +37 -0
- data/lib/brickset/version.rb +3 -0
- data/spec/brickset_spec.rb +7 -0
- data/spec/client_spec.rb +59 -0
- data/spec/configuration_spec.rb +25 -0
- data/spec/spec_helper.rb +2 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f55c7c715d91ac8a0c2b8755551d0f6e189fc4b1
|
4
|
+
data.tar.gz: e8145706a24774fae35cdd560f5e94bb545cbc97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f43eef90c5b681308f333818f2db1938c1bda47f1575a221daaf59f10f6dfd9523c82faef8038e2d325bf8fcf6c4c072cedb3d037f616ddfc87e45559af0684f
|
7
|
+
data.tar.gz: f6bd38d8c17856f8c3dc1733e1d9fbaef6dfd5cbd9e014a81e271faab8cb6eb3d5e597509df7c719a0939522d25348f939847e5e2ef6a78850b9288a54c214a0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 dbwinger
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# BricksetRubyApi
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'brickset'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install brickset
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/brickset/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/brickset.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'brickset/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "brickset"
|
8
|
+
spec.version = Brickset::VERSION
|
9
|
+
spec.authors = ["dbwinger"]
|
10
|
+
spec.email = ["dbwinger@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper for the Brickset.com v2 API}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "byebug"
|
24
|
+
|
25
|
+
spec.add_dependency "nokogiri"
|
26
|
+
spec.add_dependency "httparty"
|
27
|
+
end
|
data/lib/brickset.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module Brickset
|
4
|
+
class Client
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
# Define the same set of accessors as the Awesome module
|
8
|
+
attr_accessor *Configuration::VALID_CONFIG_KEYS
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
# Merge the config values from the module and those passed
|
12
|
+
# to the client.
|
13
|
+
merged_options = Brickset.options.merge(options)
|
14
|
+
|
15
|
+
# Copy the merged values to this client and ignore those
|
16
|
+
# not part of our configuration
|
17
|
+
Configuration::VALID_CONFIG_KEYS.each do |key|
|
18
|
+
send("#{key}=", merged_options[key])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_sets options
|
23
|
+
required_params = [:userHash, :query, :theme, :subtheme, :setNumber, :year, :owned, :wanted, :orderBy, :pageSize, :pageNumber, :userName]
|
24
|
+
default_options = {}
|
25
|
+
required_params.each { |param| default_options[param] = nil }
|
26
|
+
response = call_api(:getSets, default_options.merge(options))
|
27
|
+
if response["ArrayOfSets"].nil?
|
28
|
+
[]
|
29
|
+
else
|
30
|
+
response["ArrayOfSets"]["sets"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_recently_updated_sets minutes_ago
|
35
|
+
response = call_api :getRecentlyUpdatedSets, {minutesAgo: minutes_ago}
|
36
|
+
if response["ArrayOfSets"].nil?
|
37
|
+
[]
|
38
|
+
else
|
39
|
+
response["ArrayOfSets"]["sets"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def call_api method, options = {}
|
46
|
+
response = self.class.get("#{endpoint}/#{method.to_s}", query: options.merge(apiKey: api_key))
|
47
|
+
if response.code == 200
|
48
|
+
response.parsed_response
|
49
|
+
else
|
50
|
+
raise response.body
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Brickset
|
2
|
+
module Configuration
|
3
|
+
VALID_CONNECTION_KEYS = [:endpoint, :user_agent, :method].freeze
|
4
|
+
VALID_OPTIONS_KEYS = [:api_key].freeze
|
5
|
+
VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
|
6
|
+
|
7
|
+
DEFAULT_ENDPOINT = 'http://brickset.com/api/v2.asmx'
|
8
|
+
DEFAULT_METHOD = :get
|
9
|
+
DEFAULT_USER_AGENT = "Brickset API Ruby Gem #{Brickset::VERSION}".freeze
|
10
|
+
DEFAULT_API_KEY = ENV['BRICKSET_API_KEY']
|
11
|
+
|
12
|
+
# Build accessor methods for every config options so we can do this, for example:
|
13
|
+
# Awesome.method = :get
|
14
|
+
attr_accessor *VALID_CONFIG_KEYS
|
15
|
+
|
16
|
+
# Make sure we have the default values set when we get 'extended'
|
17
|
+
def self.extended(base)
|
18
|
+
base.reset
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset
|
22
|
+
self.endpoint = DEFAULT_ENDPOINT
|
23
|
+
self.method = DEFAULT_METHOD
|
24
|
+
self.user_agent = DEFAULT_USER_AGENT
|
25
|
+
|
26
|
+
self.api_key = DEFAULT_API_KEY
|
27
|
+
end
|
28
|
+
|
29
|
+
def configure
|
30
|
+
yield self
|
31
|
+
end
|
32
|
+
|
33
|
+
def options
|
34
|
+
Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Brickset::Client do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@keys = Brickset::Configuration::VALID_CONFIG_KEYS
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'with module configuration' do
|
10
|
+
before do
|
11
|
+
Brickset.configure do |config|
|
12
|
+
@keys.each do |key|
|
13
|
+
config.send("#{key}=", key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Brickset.reset
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should inherit module configuration" do
|
23
|
+
api = Brickset::Client.new
|
24
|
+
@keys.each do |key|
|
25
|
+
expect(api.send(key)).to eq(key)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'with class configuration' do
|
30
|
+
before do
|
31
|
+
@config = {
|
32
|
+
:api_key => 'ak',
|
33
|
+
:endpoint => 'ep',
|
34
|
+
:user_agent => 'ua',
|
35
|
+
:method => 'hm',
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should override module configuration' do
|
40
|
+
api = Brickset::Client.new(@config)
|
41
|
+
@keys.each do |key|
|
42
|
+
expect(api.send(key)).to eq(@config[key])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should override module configuration after' do
|
47
|
+
api = Brickset::Client.new
|
48
|
+
|
49
|
+
@config.each do |key, value|
|
50
|
+
api.send("#{key}=", value)
|
51
|
+
end
|
52
|
+
|
53
|
+
@keys.each do |key|
|
54
|
+
expect(api.send("#{key}")).to eq(@config[key])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'configuration' do
|
4
|
+
after { Brickset.reset }
|
5
|
+
|
6
|
+
describe '.configure' do
|
7
|
+
Brickset::Configuration::VALID_CONFIG_KEYS.each do |key|
|
8
|
+
it "should set the #{key}" do
|
9
|
+
Brickset.configure do |config|
|
10
|
+
config.send("#{key}=", key)
|
11
|
+
expect(Brickset.send(key)).to eq(key)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Brickset::Configuration::VALID_CONFIG_KEYS.each do |key|
|
18
|
+
describe ".#{key}" do
|
19
|
+
it 'should return the default value' do
|
20
|
+
expect(Brickset.send(key)).to eq(Brickset::Configuration.const_get("DEFAULT_#{key.upcase}"))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brickset
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- dbwinger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: httparty
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- dbwinger@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- brickset.gemspec
|
112
|
+
- lib/brickset.rb
|
113
|
+
- lib/brickset/client.rb
|
114
|
+
- lib/brickset/configuration.rb
|
115
|
+
- lib/brickset/version.rb
|
116
|
+
- spec/brickset_spec.rb
|
117
|
+
- spec/client_spec.rb
|
118
|
+
- spec/configuration_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
homepage: ''
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.2.2
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Ruby wrapper for the Brickset.com v2 API
|
144
|
+
test_files:
|
145
|
+
- spec/brickset_spec.rb
|
146
|
+
- spec/client_spec.rb
|
147
|
+
- spec/configuration_spec.rb
|
148
|
+
- spec/spec_helper.rb
|