Class: Thron::Gateway::Category

Inherits:
Session show all
Defined in:
lib/thron/gateway/category.rb

Constant Summary collapse

PACKAGE =
Package.new(:xcontents, :resources, self.service_name)

Constants inherited from Base

Base::NO_ACTIVE_SESSION

Instance Attribute Summary

Attributes inherited from Base

#token_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#initialize

Methods included from Pageable

included

Methods inherited from Base

#check_session, client_id, #client_id, service_name

Methods included from Routable

included, info, #route

Constructor Details

This class inherits a constructor from Thron::Gateway::Session

Class Method Details

.routesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/thron/gateway/category.rb', line 11

def self.routes
  @routes ||= {
    create_category: Route::factory(name: 'createCategory', package: PACKAGE),
    create_system_category: Route::factory(name: 'createSystemCategory', package: PACKAGE),
    add_category_for_locale: Route::factory(name: 'addCategory4Locale', package: PACKAGE),
    add_category_pretty_id: Route::factory(name: 'addCategoryPrettyId', package: PACKAGE),
    find_categories: Route::factory(name: 'findByProperties2', package: PACKAGE),
    category_detail: Route::factory(name: 'getCategory', package: PACKAGE, verb: Route::Verbs::GET),
    remove_category: Route::factory(name: 'removeCategory', package: PACKAGE),
    remove_category_for_locale: Route::factory(name: 'removeCategory4Locale', package: PACKAGE),
    remove_category_pretty_id: Route::factory(name: 'removeCategoryPrettyId', package: PACKAGE),
    set_parent_category: Route::factory(name: 'setParentId', package: PACKAGE),
    update_category: Route::factory(name: 'updateCategory', package: PACKAGE),
    update_category_for_locale: Route::factory(name: 'updateCategory4Locale', package: PACKAGE),
    update_category_pretty_id: Route::factory(name: 'updateCategoryPrettyId', package: PACKAGE)
  }
end

Instance Method Details

#add_category_for_locale(options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/thron/gateway/category.rb', line 66

def add_category_for_locale(options = {})
  category_id = options[:category_id]
  locale = options[:locale]
  body = { 
    client: {
      clientId: client_id
    },
    catId: category_id,
    catLocale: locale
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#add_category_pretty_id(options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/thron/gateway/category.rb', line 79

def add_category_pretty_id(options = {})
  category_id = options[:category_id]
  pretty_id = options[:pretty_id]
  body = { 
    clientId: client_id,
    categoryId: category_id,
    prettyId: pretty_id
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#category_detail(options = {}) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/thron/gateway/category.rb', line 111

def category_detail(options = {})
  category_id = options[:category_id]
  recursive = options.fetch(:recursive) { false }
  locale = options[:locale]
  query = { 
    clientId: client_id,
    categoryId: category_id,
    cascade: recursive,
    locale: locale
  }
  route(to: __callee__, query: query, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('category') { {} })
  end
end

#create_category(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/thron/gateway/category.rb', line 29

def create_category(options = {})
  parent_id = options[:parent_id]
  locale = options[:locale]
  is_private = options.fetch(:is_private) { false }
  solution = options[:solution]
  data = options[:data]
  body = { 
    client: {
      clientId: client_id
    },
    upCatId: parent_id,
    catLocales: locale,
    isPrivate: is_private,
    private: is_private,
    solution: solution,
    options: data
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#create_system_category(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/thron/gateway/category.rb', line 49

def create_system_category(options = {})
  category_id = options[:category_id]
  parent_id = options[:parent_id]
  locale = options[:locale]
  data = options[:data]
  body = { 
    client: {
      clientId: client_id
    },
    newCategoryId: category_id,
    upCatId: parent_id,
    catLocales: locale,
    options: data
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#find_categories(options = {}) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/thron/gateway/category.rb', line 90

def find_categories(options = {})
  criteria = options.fetch(:criteria) { {} }
  locale = options[:locale]
  order_by = options[:order_by]
  offset = options[:offset].to_i
  limit = options[:limit].to_i
  body = { 
    client: {
      clientId: client_id
    },
    properties: criteria,
    locale: locale,
    orderBy: order_by,
    offset: offset.to_i,
    numberOfResult: limit.to_i
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('categories') { [] })
  end
end

#remove_category(options = {}) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# File 'lib/thron/gateway/category.rb', line 126

def remove_category(options = {})
  category_id = options[:category_id]
  recursive = options.fetch(:recursive) { false }
  query = { 
    clientId: client_id,
    catId: category_id,
    cascade: recursive
  }
  route(to: __callee__, query: query, token_id: token_id, dash: false)
end

#remove_category_for_locale(options = {}) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/thron/gateway/category.rb', line 137

def remove_category_for_locale(options = {})
  category_id = options[:category_id]
  locale = options[:locale]
  body = { 
    client: {
      clientId: client_id
    },
    catId: category_id,
    locale: locale
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#remove_category_pretty_id(options = {}) ⇒ Object



150
151
152
153
154
155
156
157
158
159
# File 'lib/thron/gateway/category.rb', line 150

def remove_category_pretty_id(options = {})
  category_id = options[:category_id]
  locale = options[:locale]
  body = { 
    clientId: client_id,
    categoryId: category_id,
    locale: locale
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#set_parent_category(options = {}) ⇒ Object



161
162
163
164
165
166
167
168
169
170
# File 'lib/thron/gateway/category.rb', line 161

def set_parent_category(options = {})
  category_id = options[:category_id]
  parent_id = options[:parent_id]
  query = { 
    clientId: client_id,
    categoryId: category_id,
    categoryParentId: parent_id
  }
  route(to: __callee__, query: query, token_id: token_id, dash: false)
end

#update_category(options = {}) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/thron/gateway/category.rb', line 172

def update_category(options = {})
  category_id = options[:category_id]
  data = options[:data]
  body = { 
    client: {
      clientId: client_id
    },
    categoryId: category_id,
    update: data
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#update_category_for_locale(options = {}) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/thron/gateway/category.rb', line 185

def update_category_for_locale(options = {})
  category_id = options[:category_id]
  locale = options[:locale]
  body = { 
    client: {
      clientId: client_id
    },
    catId: category_id,
    property: locale
  }
  route(to: __callee__, body: body, token_id: token_id)
end

#update_category_pretty_id(options = {}) ⇒ Object



198
199
200
201
202
203
204
205
206
207
# File 'lib/thron/gateway/category.rb', line 198

def update_category_pretty_id(options = {})
  category_id = options[:category_id]
  pretty_id = options[:pretty_id]
  body = { 
    clientId: client_id,
    categoryId: category_id,
    prettyId: pretty_id
  }
  route(to: __callee__, body: body, token_id: token_id)
end