<commit_before>import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Jsonp, URLSearchParams } from '@angular/http';
import { Response, config } from '../data.types';
import { Observer } from 'rxjs/Observer';

@Injectable()
export class TumblrService {
    private baseUrl = 'https://api.tumblr.com/v2/';
    constructor( private jsonp: Jsonp) {
    }

    getPosts(blogId: string, offset: number = 0, tag?: string, id?: number): Observable<Response> {
        return Observable.create((observer: Observer<Response>) => {
            let params = new URLSearchParams();
            params.set('api_key', config.consumerKey);
            params.set('reblog_info', 'True');
            params.set('jsonp', 'JSONP_CALLBACK');
            params.set('limit', '10');
            params.set('offset', offset.toString());
            if (tag) {
                params.set('tag', tag);
            }
            if (id) {
                params.set('id', id.toString());
            }

            this.jsonp.get(this.baseUrl + 'blog/' + blogId + '/posts', { search: params })
                .map(res => {
                    let response: Response = res.json().response;
                    response.posts.forEach(post => post.date = new Date(post.date));
                    return response;
                }).subscribe(x => {
                    observer.next(x);
                    observer.complete();
                }, e => {
                    observer.error(e);
                    observer.complete();
                });
        });
    }
}<commit_msg>Simplify tumblr service<commit_after>import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Jsonp, URLSearchParams } from '@angular/http';
import { Response, config } from '../data.types';

@Injectable()
export class TumblrService {
    private baseUrl = 'https://api.tumblr.com/v2/';
    constructor( private jsonp: Jsonp) {
    }

    getPosts(blogId: string, offset: number = 0, tag?: string, id?: number): Observable<Response> {
        let params = new URLSearchParams();
        params.set('api_key', config.consumerKey);
        params.set('reblog_info', 'True');
        params.set('jsonp', 'JSONP_CALLBACK');
        params.set('limit', '10');
        params.set('offset', offset.toString());
        if (tag) {
            params.set('tag', tag);
        }
        if (id) {
            params.set('id', id.toString());
        }

        return this.jsonp.get(this.baseUrl + 'blog/' + blogId + '/posts', { search: params })
            .map(res => {
                let response: Response = res.json().response;
                response.posts.forEach(post => post.date = new Date(post.date));
                return response;
            });
    }
}
{'fraction_non_alphanumeric': 0.15354470965443534, 'fraction_numerical': 0.0028500178126113287, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '3930397', 'n_tokens_mistral': 805, 'n_tokens_neox': 763, 'n_words': 172}