Class: SearchSpring::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/search_spring/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site_id, secret_key, req_options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
# File 'lib/search_spring/client.rb', line 8

def initialize(site_id, secret_key, req_options = {})
  @site_id = site_id
  @secret_key = secret_key
  raise Errors::AuthenticationError, 'No Site ID provided.' unless @site_id
  unless @secret_key
    raise Errors::AuthenticationError, 'No Secret Key provided.'
  end

  @conn = connection(req_options)
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



6
7
8
# File 'lib/search_spring/client.rb', line 6

def conn
  @conn
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



6
7
8
# File 'lib/search_spring/client.rb', line 6

def secret_key
  @secret_key
end

#site_idObject (readonly)

Returns the value of attribute site_id.



6
7
8
# File 'lib/search_spring/client.rb', line 6

def site_id
  @site_id
end

Instance Method Details

#delete(feed_id:, product_ids: []) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/search_spring/client.rb', line 41

def delete(feed_id:, product_ids: [])
  conn.post do |req|
    req.url 'api/index/delete.json'
    req.headers['Content-Type'] = 'application/json'
    req.body = MultiJson.dump(
      feedId: feed_id,
      records: product_ids
    )
  end
end

#update(feed_id:, products: []) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/search_spring/client.rb', line 30

def update(feed_id:, products: [])
  conn.post do |req|
    req.url 'api/index/update.json'
    req.headers['Content-Type'] = 'application/json'
    req.body = MultiJson.dump(
      feedId: feed_id,
      records: products
    )
  end
end

#upsert(feed_id:, products: []) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/search_spring/client.rb', line 19

def upsert(feed_id:, products: [])
  conn.post do |req|
    req.url 'api/index/upsert.json'
    req.headers['Content-Type'] = 'application/json'
    req.body = MultiJson.dump(
      feedId: feed_id,
      records: products
    )
  end
end