Class: FastSpring::PrivateApiBase

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/fastspring-saasy/private_api_base.rb

Direct Known Subclasses

Order, Subscription

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reference) ⇒ PrivateApiBase

Returns a new instance of PrivateApiBase.



10
11
12
13
14
15
16
# File 'lib/fastspring-saasy/private_api_base.rb', line 10

def initialize(reference)
  @auth = {:username => FastSpring::Account.fetch(:username),
          :password => FastSpring::Account.fetch(:password)}
  @company = FastSpring::Account.fetch(:company)
  @reference = reference
  @ssl_ca_file = FastSpring::Account.fetch(:ssl_ca_file)
end

Instance Attribute Details

#customerObject (readonly)

Returns a customer object



8
9
10
# File 'lib/fastspring-saasy/private_api_base.rb', line 8

def customer
  @customer
end

Class Method Details

.find(reference) ⇒ Object



18
19
20
# File 'lib/fastspring-saasy/private_api_base.rb', line 18

def self.find(reference)
  self.new(reference).find
end

.search(query = "") ⇒ Object



22
23
24
# File 'lib/fastspring-saasy/private_api_base.rb', line 22

def self.search(query="")
  self.new("").search(query)
end

Instance Method Details

#referenceObject



36
37
38
# File 'lib/fastspring-saasy/private_api_base.rb', line 36

def reference
  @reference
end

#referrerObject



50
51
52
# File 'lib/fastspring-saasy/private_api_base.rb', line 50

def referrer
  value_for('referrer')
end

#search(query) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/fastspring-saasy/private_api_base.rb', line 26

def search(query)
  response = self.class.get("/company/#{@company}/orders/search?query=#{CGI::escape(query)}", :basic_auth => @auth, :ssl_ca_file => @ssl_ca_file)
  order_response = response.parsed_response['orders']['order']
  return [] if order_response.nil?

  order_response.map do |order|
    Order.new("").build_from(order)
  end
end

#source_campaignObject



62
63
64
# File 'lib/fastspring-saasy/private_api_base.rb', line 62

def source_campaign
  value_for('sourceCampaign')
end

#source_keyObject



58
59
60
# File 'lib/fastspring-saasy/private_api_base.rb', line 58

def source_key
  value_for('sourceKey')
end

#source_nameObject



54
55
56
# File 'lib/fastspring-saasy/private_api_base.rb', line 54

def source_name
  value_for('sourceName')
end

#statusObject

Returns the current status



41
42
43
# File 'lib/fastspring-saasy/private_api_base.rb', line 41

def status
  value_for('status')
end

#status_changedObject

When the status was last changed



46
47
48
# File 'lib/fastspring-saasy/private_api_base.rb', line 46

def status_changed
  DateTime.parse(value_for('statusChanged'))
end