Sha256: ce91d90363cfb9e1602024ad25ed452571b168391aeacb9d5549caf2f9a68798

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Spearly
  module Cloud
    class Client
      def initialize(token)
        @token = token
      end

      def get_sites(params)
        uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/sites"
        uri_parsed = Addressable::URI.parse(uri).normalize.to_s
        client = Faraday.default_connection

        res = client.get(uri_parsed,
                         params,
                         'Accept' => 'application/vnd.spearly.v2+json',
                         'Authorization' => @token)

        if res.status == 200
          JSON.parse(res.body)['data']
        else
          []
        end
      end

      def get_site(site_id)
        uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/sites/#{site_id}"
        uri_parsed = Addressable::URI.parse(uri).normalize.to_s
        client = Faraday.default_connection

        res = client.get(uri_parsed,
                         nil,
                         'Accept' => 'application/vnd.spearly.v2+json',
                         'Authorization' => @token)

        if res.status == 200
          JSON.parse(res.body)['data']
        else
          {}
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spearly-sdk-ruby-0.12.3 lib/spearly/cloud/client.rb
spearly-sdk-ruby-0.11.2 lib/spearly/cloud/client.rb
spearly-sdk-ruby-0.11.1 lib/spearly/cloud/client.rb
spearly-sdk-ruby-0.11.0 lib/spearly/cloud/client.rb