<commit_before># Flickr Objects

This gem is an object-oriented wrapper for the [Flickr API](http://flickr.com/api).
To see its capability, take a look at this nice demonstration:

[http://janko-m.github.com/flickr-objects/](http://janko-m.github.com/flickr-objects/)

## Installation and setup

Add it to your `Gemfile`, and run `bundle install`.

```ruby
gem "flickr-objects"
```

Now create an initializer where you set your Flickr credentials.

```ruby
Flickr.configure do |config|
  config.api_key = "API_KEY"
  config.shared_secret = "SHARED_SECRET"
end
```

If you don't have your API key and shared secret yet, you can apply for them
[here](http://www.flickr.com/services/apps/create/apply).

## Usage

Let's start with a general example.

```ruby
photos = Flickr.photos.search(user_id: "78733179@N04") #=> [#<Flickr::Photo: ...>, #<Flickr::Photo: ...>, ...]

photo = photos.first
photo.id                  #=> "231233252"
photo.title               #=> "My cat"
photo.visibility.public?  #=> true
photo.tags = "cats funny" # API request
photo.get_info!           # API request
photo.tags.join(" ")      #=> "cats funny"
```

Methods like `Flickr.photos.search` are **class** API methods, and methods like `photo.tags=` and
`photo.get_info!` are **instance** API methods.

- `Flickr.photos.search` <=> `Flickr::Photo.search`
- `photo.tags=`          <=> `Flickr::Photo#tags=`
- `photo.get_info!`      <=> `Flickr::Photo#get_info!`

API methods under the hood call methods described on Flickr's official [API page](http://flickr.com/api).
In our example, we have this correspondence:

- `Flickr::Photo.search`    <=> flickr.photos.search
- `Flickr::Photo#tags=`     <=> flickr.photos.setTags
- `Flickr::Photo#get_info!` <=> flickr.photos.getInfo

Raw Flickr's API methods always take a hash of parameters. So, for example,
flickr.people.findByEmail takes the `:find_email` parameter. But this gem
implies these kind of obvious parameters, so instead of having to call it like this:

```ruby
Flickr.people.find_by_email(find_email: "<EMAIL>")
```

you can rather call it like this:

```ruby
Flickr.people.find_by_email("<EMAIL>")
```

You can still pass a hash of other parameters as the last argument. For the
documentation on valid arguments, just look at the source code under
`lib/flickr/api/`. In our example, because `.find_by_email` belongs to `people`,
the method is located in [`lib/flickr/api/person.rb`](https://github.com/janko-m/flickr-objects/blob/master/lib/flickr/api/person.rb#L5-8).

Now, let's say that you want to use a method that fetches all sets from a
person. And you find out that this method is "flickr.photosets.getList".
How can you now find out where it is located in this gem? Well, that's where
`Flickr.api_methods` comes in handy. You can call it in the console:

```ruby
Flickr.api_methods["flickr.photosets.getList"] #=> ["Flickr::Person#get_sets"]
```

Now you found out that it is located in `Flickr::Person#get_sets`.

```ruby
# You can now call it like this:
sets = Flickr.people.find(person_id).get_sets
sets.first.id #=> "12312324"

# Or like this:
sets = Flickr.find_by_username("josh").get_sets
sets.first.id #=> "12312324"
```

## Sizes

When you upload photos to Flickr, Flickr automatically makes different versions
(sizes) of your photo. So, for example you have "Medium 500", "Small 320", and
so on. Here's how you use this in the gem:
<commit_msg>Fix a link in the readme<commit_after># Flickr Objects

This gem is an object-oriented wrapper for the [Flickr API](http://flickr.com/api).
To see its capability, take a look at this nice demonstration:

[http://janko-m.github.com/flickr-objects/](http://janko-m.github.com/flickr-objects/)

## Installation and setup

Add it to your `Gemfile`, and run `bundle install`.

```ruby
gem "flickr-objects"
```

Now create an initializer where you set your Flickr credentials.

```ruby
Flickr.configure do |config|
  config.api_key = "API_KEY"
  config.shared_secret = "SHARED_SECRET"
end
```

If you don't have your API key and shared secret yet, you can apply for them
[here](http://www.flickr.com/services/apps/create/apply).

## Usage

Let's start with a general example.

```ruby
photos = Flickr.photos.search(user_id: "78733179@N04") #=> [#<Flickr::Photo: ...>, #<Flickr::Photo: ...>, ...]

photo = photos.first
photo.id                  #=> "231233252"
photo.title               #=> "My cat"
photo.visibility.public?  #=> true
photo.tags = "cats funny" # API request
photo.get_info!           # API request
photo.tags.join(" ")      #=> "cats funny"
```

Methods like `Flickr.photos.search` are **class** API methods, and methods like `photo.tags=` and
`photo.get_info!` are **instance** API methods.

- `Flickr.photos.search` <=> `Flickr::Photo.search`
- `photo.tags=`          <=> `Flickr::Photo#tags=`
- `photo.get_info!`      <=> `Flickr::Photo#get_info!`

API methods under the hood call methods described on Flickr's official [API page](http://flickr.com/api).
In our example, we have this correspondence:

- `Flickr::Photo.search`    <=> flickr.photos.search
- `Flickr::Photo#tags=`     <=> flickr.photos.setTags
- `Flickr::Photo#get_info!` <=> flickr.photos.getInfo

Raw Flickr's API methods always take a hash of parameters. So, for example,
flickr.people.findByEmail takes the `:find_email` parameter. But this gem
implies these kind of obvious parameters, so instead of having to call it like this:

```ruby
Flickr.people.find_by_email(find_email: "<EMAIL>")
```

you can rather call it like this:

```ruby
Flickr.people.find_by_email("<EMAIL>")
```

You can still pass a hash of other parameters as the last argument. For the
documentation on valid arguments, just look at the source code under
`lib/flickr/api/`. In our example, because `.find_by_email` belongs to `people`,
the method is located in [`lib/flickr/api/person.rb`](https://github.com/janko-m/flickr-objects/blob/master/lib/flickr/api/person.rb#L3-6).

Now, let's say that you want to use a method that fetches all sets from a
person. And you find out that this method is "flickr.photosets.getList".
How can you now find out where it is located in this gem? Well, that's where
`Flickr.api_methods` comes in handy. You can call it in the console:

```ruby
Flickr.api_methods["flickr.photosets.getList"] #=> ["Flickr::Person#get_sets"]
```

Now you found out that it is located in `Flickr::Person#get_sets`.

```ruby
# You can now call it like this:
sets = Flickr.people.find(person_id).get_sets
sets.first.id #=> "12312324"

# Or like this:
sets = Flickr.find_by_username("josh").get_sets
sets.first.id #=> "12312324"
```

## Sizes

When you upload photos to Flickr, Flickr automatically makes different versions
(sizes) of your photo. So, for example you have "Medium 500", "Small 320", and
so on. Here's how you use this in the gem:

{'fraction_non_alphanumeric': 0.13801203934811335, 'fraction_numerical': 0.012626633387167817, 'mean_word_length': 4.184170471841704, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '30617', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2206, 'n_words': 741}