Class: TwitPic::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/twitpic/client.rb,
lib/twitpic/api/tags.rb,
lib/twitpic/api/faces.rb,
lib/twitpic/api/media.rb,
lib/twitpic/api/users.rb,
lib/twitpic/api/events.rb,
lib/twitpic/api/places.rb,
lib/twitpic/api/upload.rb,
lib/twitpic/api/comments.rb

Overview

Added by Clipflakes

Constant Summary collapse

@@TAGS_API =
{
  :show => {
    :endpoint => 'tags/show',
    :method => :get,
    :required => [:tag]
  },
  
  :create => {
    :endpoint => 'tags/create',
    :method => :post,
    :required => [:media_id, :tags]
  },
  
  :delete => {
    :endpoint => 'tags/delete',
    :method => :post,
    :required => [:media_id, :tag_id]
  }
}
@@FACES_API =
{
  :show => {
    :endpoint => 'faces/show',
    :method => :post,
    :required => [:user]
  },
  
  :create => {
    :endpoint => 'faces/create',
    :method => :post,
    :required => [:media_id, :top_coord, :left_coord]
  },
  
  :edit => {
    :endpoint => 'faces/edit',
    :method => :post,
    :required => [:tag_id]
  },
  
  :delete => {
    :endpoint => 'faces/delete',
    :method => :post,
    :required => [:tag_id]
  }
}
@@MEDIA_API =
{
  :show => {
    :endpoint => 'media/show',
    :method => :get,
    :required => [:id]
  }
}
@@USERS_API =
{
  :show => {
    :endpoint => 'users/show',
    :method => :get,
    :required => [:username]
  }
}
@@EVENTS_API =
{
  :show => {
    :endpoint => 'events/show',
    :method => :get,
    :required => [:user]
  }
}
@@EVENT_API =
{
  :show => {
    :endpoint => 'event/show',
    :method => :get,
    :required => [:id]
  },
  
  :create => {
    :endpoint => 'event/create',
    :method => :post,
    :required => [:name]
  },
  
  :delete => {
    :endpoint => 'event/delete',
    :method => :post,
    :required => [:event_id]
  },
  
  :add => {
    :endpoint => 'event/add',
    :method => :post,
    :required => [:media_id, :event_id]
  },
  
  :remove => {
    :endpoint => 'event/add',
    :mehtod => :post,
    :required => [:event_id, :media_id]
  }
}
@@PLACE_API =
{
  :show => {
    :endpoint => 'place/show',
    :method => :get,
    :required => [:id]
  }
}
@@PLACES_API =
{
  :show => {
    :endpoint => 'places/show',
    :method => :get,
    :required => [:user]
  }
}
@@COMMENTS_API =
{
  :show => {
    :endpoint => 'comments/show',
    :method => :get,
    :required => [:media_id, :page]
  },
  
  :create => {
    :endpoint => 'comments/create',
    :method => :post,
    :required => [:media_id, :message]
  },
  
  :delete => {
    :endpoint => 'comments/delete',
    :method => :post,
    :required => [:comment_id]
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



8
9
10
# File 'lib/twitpic/client.rb', line 8

def initialize
  @config = TwitPic::Config.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/twitpic/client.rb', line 6

def config
  @config
end

#write_enabledObject (readonly)

Determines whether all of the required information has been entered into the config so we know if we can make a write-enabled call or not. Is this too ghetto/unsafe?



21
22
23
# File 'lib/twitpic/client.rb', line 21

def write_enabled
  @write_enabled
end

Instance Method Details

#comments(action, args) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
# File 'lib/twitpic/api/comments.rb', line 22

def comments(action, args)
  raise ArgumentError, "Invalid API action given" unless @@COMMENTS_API.keys.member?(action)
  TwitPic::API.query(self, @@COMMENTS_API[action], args)
end

#configure {|@config| ... } ⇒ Object

Lets you change configuration options

Yields:

Raises:

  • (ArgumentError)


13
14
15
16
17
# File 'lib/twitpic/client.rb', line 13

def configure(&block)
  raise ArgumentError, "Block required in order to configure" unless block_given?
  
  yield @config
end

#event(action, args) ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
# File 'lib/twitpic/api/events.rb', line 47

def event(action, args)
  raise ArgumentError, "Invalid API action given" unless @@EVENT_API.keys.member?(action)
  TwitPic::API.query(self, @@EVENT_API[action], args)
end

#events(action, args) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
# File 'lib/twitpic/api/events.rb', line 42

def events(action, args)
  raise ArgumentError, "Invalid API action given" unless @@EVENTS_API.keys.member?(action)
  TwitPic::API.query(self, @@EVENTS_API[action], args)
end

#faces(action, args) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
# File 'lib/twitpic/api/faces.rb', line 28

def faces(action, args)
  raise ArgumentError, "Invalid API action given" unless @@FACES_API.keys.member?(action)
  TwitPic::API.query(self, @@FACES_API[action], args)
end

#media(action, args) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
# File 'lib/twitpic/api/media.rb', line 12

def media(action, args)
  raise ArgumentError, "Invalid API action given" unless @@MEDIA_API.keys.member?(action)
  TwitPic::API.query(self, @@MEDIA_API[action], args)
end

#place(action, args) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
# File 'lib/twitpic/api/places.rb', line 18

def place(action, args)
  raise ArgumentError, "Invalid API action given" unless @@PLACE_API.keys.member?(action)
  TwitPic::API.query(self, @@PLACE_API[action], args)
end

#places(action, args) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
# File 'lib/twitpic/api/places.rb', line 23

def places(action, args)
  raise ArgumentError, "Invalid API action given" unless @@PLACES_API.keys.member?(action)
  TwitPic::API.query(self, @@PLACES_API[action], args)
end

#tags(action, args) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
# File 'lib/twitpic/api/tags.rb', line 22

def tags(action, args)
  raise ArgumentError, "Invalid API action given" unless @@TAGS_API.keys.member?(action)
  TwitPic::API.query(self, @@TAGS_API[action], args)
end

#upload(file, message) ⇒ Object

Uploads a photo to TwitPic



4
5
6
7
8
# File 'lib/twitpic/api/upload.rb', line 4

def upload(file, message)
  message = "" unless message.strip.length > 0
  
  TwitPic::API.upload(self, file, {:message => message})
end

#upload_and_post(file, message) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/twitpic/api/upload.rb', line 10

def upload_and_post(file, message)
  message = "" unless message.strip.length > 0
  
  media = TwitPic::API.upload(self, file, {:message => message})
  if media then
    TwitPic::API.tweet(self, media)
  end
end

#users(action, args) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/twitpic/api/users.rb', line 10

def users(action, args)
  raise ArgumentError, "Invalid API action given" unless @@USERS_API.keys.member?(action)
  TwitPic::API.query(self, @@USERS_API[action], args)
end