Sha256: 3d23ba3532564ce8fa02add0d2e046e8106f662a6443fa8d717aa121e5543f39

Contents?: true

Size: 884 Bytes

Versions: 5

Compression:

Stored size: 884 Bytes

Contents

require "json"
require "net/http"

module VimeoRuby
  class Base
    class << self
      def base_uri
        "https://api.vimeo.com"
      end

      def access_token
        ENV["VIMEO_ACCESS_TOKEN"]
      end

      def client_identifier
        ENV["VIMEO_CLIENT_IDENTIFIER"]
      end

      def client_secret
        ENV["VIMEO_CLIENT_SECRET"]
      end

      def get(uri, query_params: {})
        uri = URI.parse(uri)
        uri.query = URI.encode_www_form(query_params)

        Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |https|
          request = Net::HTTP::Get.new(uri)
          request.basic_auth(client_identifier, client_secret)

          response = https.request(request)
          JSON.parse(response.body)
        end
      end
    end

    private

    def extract_vimeo_id_from_uri(vimeo_uri)
      vimeo_uri.match(/\d+/)[0].to_i
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vimeo_ruby-0.4.3 lib/vimeo_ruby/base.rb
vimeo_ruby-0.4.2 lib/vimeo_ruby/base.rb
vimeo_ruby-0.4.1 lib/vimeo_ruby/base.rb
vimeo_ruby-0.3.0 lib/vimeo_ruby/base.rb
vimeo_ruby-0.2.0 lib/vimeo_ruby/base.rb