Class: Snowshoe::Client

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

Constant Summary collapse

API_VERSION =
"http://beta.snowshoestamp.com/api/v2"

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, options = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/snowshoe/client.rb', line 5

def initialize(key, secret, options={})
  # Flexiblity for future endpoint uri changes
  api_version = options[:api_version] || API_VERSION

  @consumer = OAuth::Consumer.new(
  key,
  secret,
  {:site => api_version,
    :scheme => :header
  }
  )
end

Instance Method Details

#log_error(message) ⇒ Object



32
33
34
# File 'lib/snowshoe/client.rb', line 32

def log_error(message)
  puts "ERROR: #{self.class}: #{message}"
end

#post(body) ⇒ Object



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

def post(body)
  response = consumer.request(:post,
  "/stamp",
  nil,
  {},
  body,
  {'Content-Type' => 'application/x-www-form-urlencoded'}
  )
  return JSON.parse(response.body)
rescue => exception
  log_error(exception.message)
  []
end