Class: Brickset::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/brickset/api.rb

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



3
4
5
6
# File 'lib/brickset/api.rb', line 3

def initialize
  @client = Savon.client(wsdl: Brickset.configuration.wsdl_url, convert_request_keys_to: :none)
  @api_key = Brickset.configuration.api_key
end

Instance Method Details

#check_keyObject



69
70
71
72
# File 'lib/brickset/api.rb', line 69

def check_key
  response = call_api(:check_key)
  response.body.dig(:check_key_response, :check_key_result) == 'OK'
end

#collection_totals(user_hash) ⇒ Object



84
85
86
87
# File 'lib/brickset/api.rb', line 84

def collection_totals(user_hash)
  response = call_api(:get_collection_totals, options: {userHash: user_hash})
  Array.wrap(response.body.dig(:get_collection_totals_response, :get_collection_totals_result))
end

#instructions(id) ⇒ Object



79
80
81
82
# File 'lib/brickset/api.rb', line 79

def instructions(id)
  response = call_api(:get_instructions, options: {setID: id})
  Array.wrap(response.body.dig(:get_instructions_response, :get_instructions_result, :instructions))
end

#login(username, password) ⇒ Object



74
75
76
77
# File 'lib/brickset/api.rb', line 74

def (username, password)
  response = call_api(:login, options: {username: username, password: password})
  response.body.dig(:login_response, :login_result)
end

#minifig_collection(user_hash, query: '', owned: '', wanted: '') ⇒ Object



89
90
91
92
# File 'lib/brickset/api.rb', line 89

def minifig_collection(user_hash, query: '', owned: '', wanted: '')
  response = call_api(:get_minifig_collection, options: {userHash: user_hash, query: query, owned: owned, wanted: wanted})
  Array.wrap(response.body.dig(:get_minifig_collection_response, :get_minifig_collection_result, :minifig_collection))
end

#operationsObject



8
9
10
# File 'lib/brickset/api.rb', line 8

def operations
  @client.operations
end

#recently_updated(minutes_ago) ⇒ Object



27
28
29
30
# File 'lib/brickset/api.rb', line 27

def recently_updated(minutes_ago)
  response = call_api(:get_recently_updated_sets, options: {minutesAgo: minutes_ago})
  Array.wrap(response.body.dig(:get_recently_updated_sets_response, :get_recently_updated_sets_result, :sets))
end

#set(id, user_hash: '') ⇒ Object



64
65
66
67
# File 'lib/brickset/api.rb', line 64

def set(id, user_hash: '')
  response = call_api(:get_set, options: {userHash: user_hash, SetID: id})
  response.body.dig(:get_set_response, :get_set_result, :sets)
end

#sets(user_hash: '', query: '', theme: '', subtheme: '', set_number: '', year: '', owned: '', wanted: '', order_by: '', page_size: '', page_number: '', user_name: '') ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/brickset/api.rb', line 32

def sets(user_hash: '',
         query: '',
         theme: '',
         subtheme: '',
         set_number: '',
         year: '',
         owned: '',
         wanted: '',
         order_by: '',
         page_size: '',
         page_number: '',
         user_name: '')
  # although the docs say the parameters are optional they must all be there
  options = {
      userHash: user_hash,
      query: query,
      theme: theme,
      subtheme: subtheme,
      setNumber: set_number,
      year: year,
      owned: owned,
      wanted: wanted,
      orderBy: order_by,
      pageSize: page_size,
      pageNumber: page_number,
      userName: user_name
  }

  response = call_api(:get_sets, options: options)
  Array.wrap(response.body.dig(:get_sets_response, :get_sets_result, :sets))
end

#subthemes(theme) ⇒ Object



17
18
19
20
# File 'lib/brickset/api.rb', line 17

def subthemes(theme)
  response = call_api(:get_subthemes, options: {theme: theme})
  Array.wrap(response.body.dig(:get_subthemes_response, :get_subthemes_result, :subthemes))
end

#subthemes_for_user(user_hash, theme, owned: '', wanted: '') ⇒ Object



99
100
101
102
# File 'lib/brickset/api.rb', line 99

def subthemes_for_user(user_hash, theme, owned: '', wanted: '')
  response = call_api(:get_subthemes_for_user, options: {userHash: user_hash, theme: theme, owned: owned, wanted: wanted})
  Array.wrap(response.body.dig(:get_subthemes_for_user_response, :get_subthemes_for_user_result, :subthemes))
end

#themesObject



12
13
14
15
# File 'lib/brickset/api.rb', line 12

def themes
  response = call_api(:get_themes)
  Array.wrap(response.body.dig(:get_themes_response, :get_themes_result, :themes))
end

#themes_for_user(user_hash, owned: '', wanted: '') ⇒ Object



94
95
96
97
# File 'lib/brickset/api.rb', line 94

def themes_for_user(user_hash, owned: '', wanted: '')
  response = call_api(:get_themes_for_user, options: {userHash: user_hash, owned: owned, wanted: wanted})
  Array.wrap(response.body.dig(:get_themes_for_user_response, :get_themes_for_user_result, :themes))
end

#years(theme) ⇒ Object



22
23
24
25
# File 'lib/brickset/api.rb', line 22

def years(theme)
  response = call_api(:get_years, options: {theme: theme})
  Array.wrap(response.body.dig(:get_years_response, :get_years_result, :years))
end

#years_for_user(user_hash, theme, owned: '', wanted: '') ⇒ Object



104
105
106
107
# File 'lib/brickset/api.rb', line 104

def years_for_user(user_hash, theme, owned: '', wanted: '')
  response = call_api(:get_years_for_user, options: {userHash: user_hash, theme: theme, owned: owned, wanted: wanted})
  Array.wrap(response.body.dig(:get_years_for_user_response, :get_years_for_user_result, :years))
end