class Pushbullet::Client

Attributes

base_path[R]

TODO: Add uploads TODO: Add ephemerals TODO: Websockets TODO: Universal copy/paste TODO: Encryption TODO: Pagination TODO: Limits TODO: Date parsing TODO: Create api client creation library

key[R]

TODO: Add uploads TODO: Add ephemerals TODO: Websockets TODO: Universal copy/paste TODO: Encryption TODO: Pagination TODO: Limits TODO: Date parsing TODO: Create api client creation library

port[R]

TODO: Add uploads TODO: Add ephemerals TODO: Websockets TODO: Universal copy/paste TODO: Encryption TODO: Pagination TODO: Limits TODO: Date parsing TODO: Create api client creation library

secret[R]

TODO: Add uploads TODO: Add ephemerals TODO: Websockets TODO: Universal copy/paste TODO: Encryption TODO: Pagination TODO: Limits TODO: Date parsing TODO: Create api client creation library

Public Class Methods

api_version() click to toggle source

This is the version of the API docs this client was built off-of

# File lib/pushbullet/client.rb, line 38
def self.api_version
  'v2 2020-10-17'
end
compatible_api_version() click to toggle source
# File lib/pushbullet/client.rb, line 33
def self.compatible_api_version
  'v2'
end
new(access_token:, base_path: API_V2_BASE_PATH, port: 80, limit: 500) click to toggle source
# File lib/pushbullet/client.rb, line 26
def initialize(access_token:, base_path: API_V2_BASE_PATH, port: 80, limit: 500)
  @access_token = access_token
  @base_path = base_path
  @port = port
  @limit = limit
end

Private Instance Methods

authorise_and_send(http_method:, path:, payload: {}, params: {}) click to toggle source
# File lib/pushbullet/client.rb, line 44
def authorise_and_send(http_method:, path:, payload: {}, params: {})
  start_time = micro_second_time_now

  if params.nil? || params.empty?
    params = {}
  end

  params['limit'] = @limit

  response = HTTParty.send(
    http_method.to_sym,
    construct_base_path(path, params),
    body: payload,
    headers: {
      'Access-Token': @access_token,
      'Content-Type': 'application/json'
    },
    port: port,
    format: :json
  )

  end_time = micro_second_time_now
  construct_response_object(response, path, start_time, end_time)
end
body_is_missing?(response) click to toggle source
# File lib/pushbullet/client.rb, line 92
def body_is_missing?(response)
  response.body.nil? || response.body.empty?
end
body_is_present?(response) click to toggle source
# File lib/pushbullet/client.rb, line 88
def body_is_present?(response)
  !body_is_missing?(response)
end
construct_base_path(path, params) click to toggle source
# File lib/pushbullet/client.rb, line 112
def construct_base_path(path, params)
  constructed_path = "#{base_path}/#{path}"

  if params == {}
    constructed_path
  else
    "#{constructed_path}?#{process_params(params)}"
  end
end
construct_metadata(response, start_time, end_time) click to toggle source
# File lib/pushbullet/client.rb, line 77
def construct_metadata(response, start_time, end_time)
  total_time = end_time - start_time

  {
    'start_time' => start_time,
    'end_time' => end_time,
    'total_time' => total_time,
    'cursor' => response.dig('cursor')
  }
end
construct_response_object(response, path, start_time, end_time) click to toggle source
# File lib/pushbullet/client.rb, line 69
def construct_response_object(response, path, start_time, end_time)
  {
    'body' => parse_body(response, path),
    'headers' => response.headers,
    'metadata' => construct_metadata(response, start_time, end_time)
  }
end
micro_second_time_now() click to toggle source
# File lib/pushbullet/client.rb, line 108
def micro_second_time_now
  (Time.now.to_f * 1_000_000).to_i
end
parse_body(response, path) click to toggle source
# File lib/pushbullet/client.rb, line 96
def parse_body(response, path)
  parsed_response = JSON.parse(response.body) # Purposely not using HTTParty

  if parsed_response.dig(path.to_s)
    parsed_response.dig(path.to_s)
  else
    parsed_response
  end
rescue JSON::ParserError => _e
  response.body
end
process_cursor(cursor, params: {}) click to toggle source
# File lib/pushbullet/client.rb, line 126
def process_cursor(cursor, params: {})
  unless cursor.nil? || cursor.empty?
    params['cursor'] = cursor
  end
end
process_params(params) click to toggle source
# File lib/pushbullet/client.rb, line 122
def process_params(params)
  params.keys.map { |key| "#{key}=#{params[key]}" }.join('&')
end