motion-prime/api_client.rb in motion-prime-0.5.3 vs motion-prime/api_client.rb in motion-prime-0.5.4

- old
+ new

@@ -36,18 +36,17 @@ client_id: config.client_id, client_secret: config.client_secret } use_callback = block_given? BW::HTTP.post("#{config.base}#{config.auth_path}", request_params(data)) do |response| - access_token = if response.ok? - json = parse_json(response.body) - json[:access_token] + auth_data = if response.ok? + parse_json(response.body) else false end - self.access_token = access_token - block.call(access_token) if use_callback + self.access_token = auth_data[:access_token] if auth_data + block.call(auth_data, response.status_code) if use_callback end true end def api_url(path) @@ -110,20 +109,21 @@ options[:allow_queue] = true unless options.has_key?(:allow_queue) request(:delete, path, params, options, &block) end private - def user_defaults - @user_defaults ||= NSUserDefaults.standardUserDefaults + + def config + MotionPrime::Config.api_client end def parse_json(text) Prime::JSON.parse(text) rescue NSLog("Can't parse json: #{text}") false end - - def config - MotionPrime::Config.api_client + + def user_defaults + @user_defaults ||= NSUserDefaults.standardUserDefaults end end \ No newline at end of file