Sha256: 746b09f9f0d3008a8cc319f97bc17babd08fdc330129240640840c89f1523bc4

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

module PhoneGap
  module Build
    class ApiRequest

      include HTTMultiParty
      base_uri 'https://build.phonegap.com/api/v1'

      def get(path)
        if credentials?
          self.class.get("#{path}?auth_token=#{token}")
        else
          credentials_not_found
        end
      end

      def post(path, params = {})
        if credentials?
          self.class.post("#{path}?auth_token=#{token}", query: params[:query])
        else
          credentials_not_found
        end
      end

      def put(path, params = {})
        if credentials?
          self.class.put("#{path}?auth_token=#{token}", query: params[:query])
        else
          credentials_not_found
        end
      end

      def delete(path, params = {})
        if credentials?
          self.class.delete("#{path}?auth_token=#{token}")
        else
          credentials_not_found
        end
      end

      private

      def credentials?
        if PhoneGap::Build::Credentials.instance.token
          true
        else
          Credentials.instance.load
          PhoneGap::Build::Credentials.instance.token
        end
      end

      def credentials_not_found
        Error.new(message: 'Api credentials not found. Set them or add them to config/phonegap.yml')
      end

      def token
        PhoneGap::Build::Credentials.instance.token
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
phone_gap-build-0.7.0 lib/phone_gap/build/api_request.rb
phone_gap-build-0.6.2 lib/phone_gap/build/api_request.rb
phone_gap-build-0.6.1 lib/phone_gap/build/api_request.rb
phone_gap-build-0.6.0 lib/phone_gap/build/api_request.rb
phone_gap-build-0.5.1 lib/phone_gap/build/api_request.rb
phone_gap-build-0.5.0 lib/phone_gap/build/api_request.rb
phone_gap-build-0.4.0 lib/phone_gap/build/api_request.rb